:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #677080;
  --border: #dde1e7;
  --accent: #2f6fdb;
  --accent-text: #ffffff;
  --hover: #eef2f8;
  --active: #dfe8fa;
  --warn-bg: #fff6e0;
  --warn-text: #7a5300;
  --error: #c0362c;
  --grid: #e7eaef;
  --grid-major: #cfd5de;
  --c0: #2f6fdb;
  --c1: #d9480f;
  --c2: #2b9348;
  --c3: #9c36b5;
  --c4: #c2185b;
  --c5: #0b7285;
  --c6: #8a6d00;
  --c7: #495057;
  --sum: #1c2026;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e4e7ec;
    --muted: #949cab;
    --border: #2d333d;
    --accent: #5b92f0;
    --accent-text: #0d1117;
    --hover: #232933;
    --active: #26344d;
    --warn-bg: #3a2f12;
    --warn-text: #f1cf7a;
    --error: #ff7b72;
    --grid: #252a33;
    --grid-major: #353c48;
    --c0: #6ea2ff;
    --c1: #ff8a4c;
    --c2: #5bd27a;
    --c3: #d38cf0;
    --c4: #ff6fa3;
    --c5: #4fc7dc;
    --c6: #e0c04d;
    --c7: #b5bdc8;
    --sum: #e4e7ec;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, pre, .preview { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand span { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }
.loaders { display: flex; gap: 8px; }
.status { margin-left: auto; color: var(--muted); font-size: 13px; text-align: right; }
.status.error { color: var(--error); }

.button, button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: var(--text); font: inherit; cursor: pointer;
}
.button:hover, button:hover { background: var(--hover); }
.button input[type=file] { display: none; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--warn-bg); color: var(--warn-text);
  border-bottom: 1px solid var(--border);
}

.main { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 340px; flex-shrink: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--panel); min-height: 0;
}
.search {
  margin: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.hint { padding: 0 14px 8px; color: var(--muted); font-size: 12px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree { overflow-y: auto; flex: 1; padding-bottom: 24px; }
.group-title {
  width: 100%; justify-content: space-between; border: 0; border-radius: 0;
  padding: 7px 14px; font-weight: 600; background: transparent; text-align: left;
}
.count { color: var(--muted); font-weight: 400; font-size: 12px; }
.item {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 5px 14px 5px 26px; cursor: pointer; font-size: 13px;
}
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 12px; flex-shrink: 0; }

.content { flex: 1; overflow-y: auto; padding: 20px 24px 48px; min-width: 0; }
.empty { max-width: 560px; margin: 80px auto; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); }
.empty.error { color: var(--error); }

.preset { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.preset-head h1 { margin: 2px 0 6px; font-size: 24px; }
.app-name { font-weight: 400; color: var(--muted); margin-left: 10px; font-size: 18px; }
.crumbs { color: var(--muted); font-size: 13px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 12px; }
.badge.file { font-family: ui-monospace, Menlo, Consolas, monospace; }
.description { color: var(--muted); margin: 8px 0 0; white-space: pre-wrap; }

.card, .plot-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
}
.card h2, .card h3, .plot-card h2 { margin: 0 0 10px; font-size: 15px; display: flex; align-items: center; gap: 8px; }

.plot-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.plot-head h2 { margin: 0; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.toggles { margin-left: auto; display: flex; gap: 12px; font-size: 13px; }
.toggles label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.plot-wrap { width: 100%; aspect-ratio: 1000 / 360; cursor: crosshair; }
.plot-wrap.phase { margin-top: 8px; }
.plot { width: 100%; height: 100%; display: block; }
.plot .grid { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.plot .grid.major { stroke: var(--grid-major); }
.plot .grid.zero { stroke: var(--muted); }
.plot .axis { fill: var(--muted); font-size: 11px; }
.plot .curve { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.plot .curve.sum { stroke: var(--sum); stroke-dasharray: 6 4; stroke-width: 1.5; }
.plot .cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.readout { min-height: 20px; color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

.swatch { display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--c0); vertical-align: middle; margin-right: 4px; }
.swatch.sum { background: var(--sum); height: 2px; }
.c0 { stroke: var(--c0); } .swatch.c0 { background: var(--c0); }
.c1 { stroke: var(--c1); } .swatch.c1 { background: var(--c1); }
.c2 { stroke: var(--c2); } .swatch.c2 { background: var(--c2); }
.c3 { stroke: var(--c3); } .swatch.c3 { background: var(--c3); }
.c4 { stroke: var(--c4); } .swatch.c4 { background: var(--c4); }
.c5 { stroke: var(--c5); } .swatch.c5 { background: var(--c5); }
.c6 { stroke: var(--c6); } .swatch.c6 { background: var(--c6); }
.c7 { stroke: var(--c7); } .swatch.c7 { background: var(--c7); }

.warnings {
  margin: 0; padding: 10px 16px 10px 32px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 13px;
}

.ways { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.kv > span:nth-child(odd) { color: var(--muted); }
.kv.limiters { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
table.eq { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
table.eq th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: 3px 4px; }
table.eq td { padding: 3px 4px; border-bottom: 1px solid var(--grid); }

.export-controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.export-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.export-controls label.inline { flex-direction: row; align-items: center; padding-bottom: 8px; color: var(--text); font-size: 13px; }
.export-controls select, .export-controls input[type=text] {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; min-width: 120px;
}
.export-controls button { margin-left: auto; }
.preview {
  margin: 12px 0 0; max-height: 340px; overflow: auto; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; white-space: pre;
}

@media (max-width: 800px) {
  .main { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .content { padding: 16px; }
  .topbar { flex-wrap: wrap; }
  .status { margin-left: 0; text-align: left; width: 100%; }
}
