:root {
	--bg: #f6f4ef;
	--panel: #ffffff;
	--ink: #1f2328;
	--muted: #6b6f76;
	--line: #dedad2;
	--accent: #2563a8;
	--accent-soft: #dbe7f5;
	--meas: #d9622b;
	--good: #2e7d4f;
	--warn: #b7791f;
	--bad: #c0392b;
	--wood: #d8b27a;
	--wood-edge: #9c7440;
	--wood2: #c99a5b;
	--felt: #efe7d6;
	--felt-edge: #b8ab90;
	--hammer-felt: #f3efe4;
	--leather: #8a5a3b;
	--metal: #8d9399;
	--metal-edge: #5d6369;
	--frame: #cfc6b6;
	--frame-edge: #a39a8a;
	--string: #6b6f76;
	--contact: #d63a2f;
	--keytop: #fbfbf8;
	--lead: #7a7f86;
	--grid: #ece8e0;
	--shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #16181b;
		--panel: #1f2226;
		--ink: #e8e6e1;
		--muted: #9aa0a6;
		--line: #33373d;
		--accent: #6ea8e8;
		--accent-soft: #1f3550;
		--meas: #f08a52;
		--good: #5cc38a;
		--warn: #e0b04f;
		--bad: #ef6b5d;
		--wood: #9c7a4d;
		--wood-edge: #c9a36b;
		--wood2: #86653c;
		--felt: #5b5548;
		--felt-edge: #8f8570;
		--hammer-felt: #cfc8b6;
		--leather: #b98561;
		--metal: #9aa0a6;
		--metal-edge: #c3c8cd;
		--frame: #3a3833;
		--frame-edge: #5c574e;
		--string: #b4b9bf;
		--contact: #ff6b5e;
		--keytop: #e9e7e1;
		--lead: #9aa0a6;
		--grid: #2a2d32;
		color-scheme: dark;
	}
}

:root[data-theme="dark"] {
	--bg: #16181b; --panel: #1f2226; --ink: #e8e6e1; --muted: #9aa0a6; --line: #33373d;
	--accent: #6ea8e8; --accent-soft: #1f3550; --meas: #f08a52; --good: #5cc38a; --warn: #e0b04f; --bad: #ef6b5d;
	--wood: #9c7a4d; --wood-edge: #c9a36b; --wood2: #86653c; --felt: #5b5548; --felt-edge: #8f8570;
	--hammer-felt: #cfc8b6; --leather: #b98561; --metal: #9aa0a6; --metal-edge: #c3c8cd; --frame: #3a3833;
	--frame-edge: #5c574e; --string: #b4b9bf; --contact: #ff6b5e; --keytop: #e9e7e1; --lead: #9aa0a6; --grid: #2a2d32;
	color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
	background: var(--bg);
	color: var(--ink);
	font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
	display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
	padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
	position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 16px; margin: 0 8px 0 0; font-weight: 650; letter-spacing: .01em; }
header .sub { color: var(--muted); font-size: 12px; }
header .spacer { flex: 1; }

button, .btn {
	font: inherit; font-size: 13px; color: var(--ink); background: var(--panel);
	border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
	white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button.small { font-size: 12px; padding: 2px 7px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main {
	display: grid; gap: 14px; padding: 14px 16px 40px;
	grid-template-columns: minmax(0, 1fr) 380px;
	max-width: 1700px; margin: 0 auto;
}
@media (max-width: 1100px) { main { grid-template-columns: 1fr; } }

.card {
	background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
	box-shadow: var(--shadow); padding: 12px 14px; min-width: 0;
}
.card h2 {
	font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
	margin: 0 0 8px; font-weight: 650; display: flex; align-items: center; gap: 8px;
}
.card h2 .grow { flex: 1; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

#actionSvg { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 8px; }
#chartSvg { width: 100%; height: 340px; display: block; }

.scrub { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.scrub input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.readout { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; min-width: 250px; }
.readout b { color: var(--ink); }

.contacts { margin-top: 6px; font-size: 12px; color: var(--muted); min-height: 18px; }
.contacts span { display: inline-block; margin: 2px 8px 0 0; }
.contacts span::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--contact); margin-right: 4px; vertical-align: 1px; }

table.metrics { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
table.metrics th, table.metrics td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--line); }
table.metrics th:first-child, table.metrics td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
table.metrics thead th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
td.dpos { color: var(--bad); } td.dneg { color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .two { grid-template-columns: 1fr; } }
.notes { margin: 8px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.notes li { color: var(--warn); margin-top: 3px; }
.notes li::before { content: "⚠ "; }

/* Parameter editor */
.pgroup { border-top: 1px solid var(--line); }
.pgroup:first-of-type { border-top: 0; }
.pgroup summary {
	cursor: pointer; padding: 7px 0; font-weight: 600; font-size: 13px; list-style: none;
	display: flex; align-items: center; gap: 6px;
}
.pgroup summary::-webkit-details-marker { display: none; }
.pgroup summary::before { content: "▸"; color: var(--muted); font-size: 11px; width: 10px; }
.pgroup[open] summary::before { content: "▾"; }
.pgroup summary .cnt { color: var(--accent); font-weight: 600; font-size: 11px; }
.prow {
	display: grid; grid-template-columns: minmax(0, 1fr) 86px 44px; gap: 6px; align-items: center;
	padding: 2px 0 2px 14px; font-size: 12.5px;
}
.prow label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow label .tag { font-size: 10px; color: var(--accent); border: 1px solid var(--accent-soft); background: var(--accent-soft); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.prow input {
	width: 100%; font: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right;
	padding: 2px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--ink);
}
.prow input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.prow.changed input { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--bg)); }
.prow .u { color: var(--muted); font-size: 11px; }
.prow:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); border-radius: 5px; }
.pfilter { width: 100%; font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); margin-bottom: 6px; }
#params { max-height: 70vh; overflow: auto; padding-right: 4px; }

/* Diagnosis */
.progress { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }
.cause { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
.cause .hd { display: flex; align-items: baseline; gap: 8px; }
.cause .rank { color: var(--muted); font-size: 12px; width: 16px; }
.cause .name { font-weight: 600; flex: 1; }
.cause .pct { font-variant-numeric: tabular-nums; font-weight: 650; }
.cause .bar { height: 4px; background: var(--grid); border-radius: 2px; margin: 5px 0 4px 24px; }
.cause .bar > div { height: 100%; border-radius: 2px; background: var(--good); }
.cause .det { margin-left: 24px; font-size: 12.5px; color: var(--muted); }
.cause .det b { color: var(--ink); font-weight: 600; }
.cause .amb { margin-left: 24px; font-size: 12px; color: var(--warn); margin-top: 3px; }
.cause .act { margin: 6px 0 0 24px; display: flex; gap: 6px; }
.muted { color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.meas-label { font-size: 12.5px; color: var(--meas); font-weight: 600; }
select { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); max-width: 220px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; vertical-align: 3px; margin-right: 5px; }
.legend i.dash { border-top-style: dashed; }

.busy { position: fixed; right: 16px; bottom: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: var(--shadow); display: none; }
.busy.on { display: block; }

/* ---- Fault atlas ---------------------------------------------------------- */
main.atlas { grid-template-columns: 1fr; max-width: 1400px; }
header a.btn { text-decoration: none; }
.lookup { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 12px; }
@media (max-width: 520px) { .lookup { grid-template-columns: 1fr; } }
.lk-fam { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.lk-fam h3 { margin: 0; font-size: 13.5px; }
.lk-fam .hint { margin: 2px 0 6px; }
.lk-row { display: grid; grid-template-columns: 180px 1fr; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
@media (max-width: 520px) { .lk-row { grid-template-columns: 1fr; } }
.lk-see { color: var(--muted); }
.lk-causes { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
	display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; text-decoration: none;
	color: var(--ink); background: var(--accent-soft); border: 1px solid transparent;
}
.chip:hover { border-color: var(--accent); }
.atlas-table td, .atlas-table th { white-space: nowrap; }
.atlas-table td:first-child a { color: var(--ink); text-decoration: none; }
.atlas-table td:first-child a:hover { color: var(--accent); }
.atlas-table td.dir { color: var(--muted); font-size: 12px; text-align: left; }
.strip { display: block; border-radius: 2px; }
.atlas-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 14px; }
@media (max-width: 460px) { .atlas-cards { grid-template-columns: 1fr; } }
.acard { scroll-margin-top: 70px; }
.acard:target { outline: 2px solid var(--accent); }
.acard .fam { font-size: 11px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; text-align: right; }
.achart { width: 100%; height: 210px; display: block; }
.acase { font-size: 12.5px; margin-top: 6px; padding-left: 8px; border-left: 3px solid; }
.acase.lo { border-color: var(--accent); }
.acase.hi { border-color: var(--meas); }

/* ---- Piano scan -------------------------------------------------------------- */
.scan-table td.wrap { white-space: normal; text-align: left; min-width: 160px; }
.scan-table thead th { text-align: left; }
.scan-table td:first-child a { color: var(--ink); font-weight: 600; text-decoration: none; }
.scan-table tr.sel td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tier { display: inline-block; min-width: 34px; text-align: center; border-radius: 9px; padding: 0 6px; font-weight: 650; color: #fff; }
.tier.flag { background: var(--bad); }
.tier.watch { background: var(--warn); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
ol.hint { margin: 4px 0 0; padding-left: 22px; }
ul.pnotes { list-style: none; padding: 0; margin: 0 0 10px; }
ul.pnotes li { padding: 6px 0 6px 26px; border-bottom: 1px solid var(--line); position: relative; font-size: 13.5px; }
ul.pnotes li::before { position: absolute; left: 4px; top: 6px; font-weight: 700; }
ul.pnotes li.s0::before { content: "\2713"; color: var(--good); }
ul.pnotes li.s1::before { content: "!"; color: var(--warn); left: 8px; }
ul.pnotes li.s2::before { content: "\26a0"; color: var(--bad); }
ul.pnotes li .ncause { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.targets { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px 18px; }
td.good { color: var(--good); } td.warnc { color: var(--warn); font-weight: 600; } td.badc { color: var(--bad); font-weight: 600; }

/* ---- KMD viewer ---------------------------------------------------------------- */
main.viewer { grid-template-columns: minmax(0, 1fr) 330px; }
@media (max-width: 1000px) { main.viewer { grid-template-columns: 1fr; } }
.keybar { display: flex; align-items: center; gap: 8px; }
.keybar .keylabel { min-width: 170px; font-size: 15px; }
.keybar input[type=range] { flex: 1; accent-color: var(--accent); }
svg.keyboard { width: 100%; height: 46px; display: block; margin: 8px 0 6px; }
svg.vchart { width: 100%; height: 400px; display: block; }
.yrange { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; margin-top: 6px; }
.yrange input[type=range] { width: 130px; accent-color: var(--accent); }
.yrange .spacer { flex: 1; }
.panel label.tog { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.panel label.tog input[type=number] { font: inherit; font-size: 12px; padding: 1px 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--ink); }
.seg.wide { display: flex; margin-bottom: 8px; }
.seg.wide button { flex: 1; }
table.vals { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
table.vals td { padding: 2px 0; border-top: 1px solid var(--line); font-size: 13px; }
table.vals td:nth-child(2) { text-align: right; font-weight: 600; }
table.vals td.cmp { text-align: right; color: var(--muted); font-size: 12px; width: 48px; }
.toolbtns { display: grid; gap: 6px; }
.pins { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.vtable th.sortable { cursor: pointer; user-select: none; }
.vtable thead th { position: sticky; top: 0; background: var(--panel); }
.vtable tbody tr { cursor: pointer; }
.vtable tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.vtable tbody tr.sel td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tooltip { position: fixed; z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
	font-size: 12px; box-shadow: var(--shadow); pointer-events: none; font-variant-numeric: tabular-nums; }

/* ---- dual (low/high) axis sliders, after the KMD GUI's ------------------------- */
.chartgrid { display: grid; grid-template-columns: 30px minmax(0, 1fr); grid-template-rows: auto 30px; column-gap: 4px; }
.dual { position: relative; touch-action: none; user-select: none; }
.dual-h { height: 30px; margin: 0 12px 0 46px; }          /* align with the plot area */
.dual-v { width: 30px; margin: 10px 0 34px; }
.dual-track { position: absolute; background: #d3d3d3; border: 1.5px solid #3a3a3a; border-radius: 6px; cursor: pointer; }
.dual-h .dual-track { left: 0; right: 0; top: 11px; height: 8px; }
.dual-v .dual-track { top: 0; bottom: 0; left: 11px; width: 8px; }
.dual-fill { position: absolute; background: var(--accent); border-radius: 4px; cursor: grab; opacity: .85; }
.dual-h .dual-fill { top: 12.5px; height: 5px; }
.dual-v .dual-fill { left: 12.5px; width: 5px; }
.dual-fill.active { cursor: grabbing; }
.dual-h1, .dual-h2 {
	position: absolute; width: 22px; height: 22px; border-radius: 7px; background: #daa520; border: 2.5px solid #1f1f1f;
	box-sizing: border-box; cursor: grab; z-index: 2;
}
.dual-h .dual-h1, .dual-h .dual-h2 { top: 4px; transform: translateX(-50%); }
.dual-v .dual-h1, .dual-v .dual-h2 { left: 4px; transform: translateY(50%); }
.dual-h1.active, .dual-h2.active, .dual-h1:focus-visible, .dual-h2:focus-visible { background: #3477f3; outline: none; }
.rangeinfo { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.rangeinfo button { margin-left: auto; }
