:root {
  --bg: #0f1318;
  --panel: #171c23;
  --line: #262d37;
  --text: #e6e8eb;
  --muted: #8d96a3;
  --accent: #3a8bff;
  --ch1: #f5d142;
  --ch2: #3ad7e6;
  --warn: #f0a03c;
  --ok: #3cc46b;
  --ctl: #11161c;
  --field: #0d1116;
  --sc-bg: #0b0f14;
  --sc-ch1: #f5d142;
  --sc-ch2: #3ad7e6;
  --sc-grid: rgba(255,255,255,0.09);
  --sc-axis: rgba(255,255,255,0.24);
  --sc-text: #8d96a3;
  --sc-xy: rgba(120,230,140,0.85);
  --sc-ok: #3cc46b;
  --sc-mark: rgba(240,160,60,0.5);
  color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #d5dbe3;
  --text: #1a1f26;
  --muted: #5a6472;
  --accent: #1f6fe5;
  --ch1: #b07800;
  --ch2: #0a8a9c;
  --warn: #b35f00;
  --ok: #1d9a4c;
  --ctl: #f3f5f8;
  --field: #ffffff;
  --sc-bg: #fbfcfd;
  --sc-ch1: #c98a00;
  --sc-ch2: #0a93a6;
  --sc-grid: rgba(0,0,0,0.08);
  --sc-axis: rgba(0,0,0,0.28);
  --sc-text: #5a6472;
  --sc-xy: #1d9a4c;
  --sc-ok: #1d9a4c;
  --sc-mark: rgba(200,110,0,0.55);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; color: inherit; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.brand b { font-size: 17px; letter-spacing: .3px; }
.by { color: var(--muted); margin-left: 8px; font-size: 13px; }
.lang, .themebtn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--ctl); color: var(--text); text-decoration: none; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.lang:hover, .themebtn:hover { border-color: var(--accent); }
.lang::before { content: "🌐"; font-size: 14px; }
.themebtn.inst { background: var(--ok); border-color: var(--ok); color: #08130c; }
.themebtn.inst[hidden] { display: none; }
.inst-help { max-width: min(420px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 10px; padding: 20px; background: var(--panel); color: var(--text); }
.inst-help::backdrop { background: rgba(0, 0, 0, .6); }
.inst-help h2 { margin: 0 0 10px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.inst-help p { margin: 0 0 16px; line-height: 1.5; }
.inst-help button { float: right; padding: 6px 18px; border: 0; border-radius: 4px; background: var(--ok); color: #08130c; font-weight: 700; cursor: pointer; }
.app { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 12px; padding: 12px; }
.topr { display: flex; align-items: center; gap: 12px; }
.srcbox { margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.srclab { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.seg.src button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 8px; white-space: normal; }
.seg.src button b { font-size: 15px; }
.seg.src button small { font-size: 12px; opacity: .85; }
.seg.src button.on { box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.srcdesc { margin: 8px 0 0; font-size: 13px; color: var(--text); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.head { justify-content: space-between; margin-bottom: 10px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0; }
.run { min-width: 110px; padding: 9px 18px; border: 0; border-radius: 4px; background: var(--ok); color: #08130c; font-weight: 700; cursor: pointer; }
.run.live { background: #e5484d; color: #fff; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { flex: 1; padding: 8px 6px; background: var(--ctl); border: 0; border-right: 1px solid var(--line); cursor: pointer; color: var(--muted); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.seg.small button { padding: 6px 6px; font-size: 13px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 30%; border-bottom: 1px solid var(--line); }
.seg.col { flex-direction: column; }
.seg.col button { border-right: 0; border-bottom: 1px solid var(--line); text-align: left; padding: 8px 10px; }
.grp { margin-top: 14px; }
.grp > label, .field > label, .cols3 label { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.field { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.field > label { margin: 0; min-width: 90px; }
.field output { min-width: 78px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.numu { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.numu input { width: 64px; text-align: right; }
input.wide { width: 100%; }
input[type=number], select { background: var(--field); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; }
.freq { display: flex; align-items: baseline; gap: 6px; }
.freq input { width: 132px; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.freqrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.presets.fgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-top: 0; flex: 1 1 150px; }
.presets.fgrid button { padding: 5px 2px; }
.freq span { color: var(--muted); font-size: 16px; }
.presets { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.presets button { flex: 1 1 auto; padding: 5px 6px; background: var(--ctl); border: 1px solid var(--line); border-radius: 3px; cursor: pointer; color: var(--muted); font-size: 12px; }
.presets button:hover { color: var(--text); }
.cols3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cols3 input { width: 100%; }
.unit { display: flex; align-items: center; gap: 4px; }
.unit input { flex: 1 1 auto; width: auto; min-width: 0; }
.unit em { font-style: normal; color: var(--muted); font-size: 13px; }
.chk { display: inline-flex; align-items: center; gap: 6px; margin: 8px 14px 0 0; color: var(--muted); cursor: pointer; }
.now { margin-top: 8px; color: var(--muted); }
.now b { color: var(--text); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.hint.warn { color: var(--warn); }
#scope { width: 100%; height: max(300px, calc(100vh - 560px)); display: block; border-radius: 4px; background: var(--sc-bg); }
.ctrls { margin-top: 10px; }
.ctrls label:not(.chk) { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.ch1, .ch1 td:first-child { color: var(--ch1); }
.ch2, .ch2 td:first-child { color: var(--ch2); }
table.meas { width: 100%; border-collapse: collapse; margin-top: 10px; font-variant-numeric: tabular-nums; }
.meas th { text-align: right; color: var(--muted); font-weight: 400; font-size: 12px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.meas td { text-align: right; padding: 6px 8px; color: var(--text); border-bottom: 1px solid var(--line); }
.meas td:first-child, .meas th:first-child { text-align: left; }
[hidden] { display: none !important; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  #scope { height: 46vh; }
}
.btn { padding: 6px 12px; background: var(--ctl); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.inrow { margin-bottom: 4px; }
.inrow .hint { margin: 0; }
#inDev { max-width: 320px; }
#inHelp { margin: 0 0 8px; }
.scopep .row.head { gap: 8px; }
#gainRow td { color: var(--ok); font-weight: 600; }
.seg button { white-space: nowrap; }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
#mode { gap: 6px; border: 0; overflow: visible; }
#mode button { flex: none; padding: 7px 14px; font-size: 14px; border: 1px solid var(--line); border-radius: 5px; }
#mode button.on { border-color: var(--accent); }
#kind button { flex: 1 1 22%; }
.dw { display: block; width: 100%; height: 170px; border-radius: 4px; border: 1px solid var(--line); cursor: crosshair; touch-action: none; }
.hhead, .hrow { display: grid; grid-template-columns: 62px minmax(0, 1fr) 40px 50px 24px 24px; gap: 4px; align-items: center; }
.hhead { margin-top: 10px; padding: 0 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.hlist { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.hrow { padding: 3px 4px; border-bottom: 1px solid var(--line); }
.hrow:last-child { border-bottom: 0; }
.hrow.off { opacity: .35; }
.hrow.quiet .ha, .hrow.quiet output { opacity: .4; }
.hk { font-weight: 700; font-size: 13px; line-height: 1.1; }
.hk small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
.hrow output { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.hrow .hp { width: 100%; padding: 3px 4px; text-align: right; }
.hrow button { height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 3px; background: var(--ctl); color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; }
.hrow .hs.on { background: var(--warn); color: #1b1206; border-color: var(--warn); }
.hrow .hm.on { background: #e5484d; color: #fff; border-color: #e5484d; }
.measp { grid-column: 2; }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mgrid .box { border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; min-width: 0; }
.mgrid .box.wide { grid-column: 1 / -1; }
.box h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 8px 6px 0; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); }
.harm { color: var(--muted); font-size: 12px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.hgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin-top: 4px; }
.hgrid div { display: flex; flex-direction: column; align-items: center; padding: 3px 0; border: 1px solid var(--line); border-radius: 4px; }
.hgrid i { font-style: normal; font-size: 11px; }
.hgrid b { color: var(--text); font-size: 13px; white-space: nowrap; }
#calV { width: 110px; }
.hint.ok { color: var(--ok); }
#resp { width: 100%; height: 260px; display: block; margin-top: 8px; border-radius: 4px; }
@media (max-width: 900px) { .measp { grid-column: 1; } .mgrid { grid-template-columns: 1fr; } }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; }

@media (min-width: 1200px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; overflow: hidden; }
  .top { flex: none; }
  .app { flex: 1 1 auto; min-height: 0; grid-template-columns: 350px minmax(0, 1fr) 350px; grid-template-rows: minmax(0, 1fr); }
  .app > .panel { min-height: 0; overflow: auto; }
  .gen { grid-column: 1; }
  .scopep { grid-column: 2; display: flex; flex-direction: column; }
  .measp { grid-column: 3; grid-row: 1; }
  #scope { flex: 1 1 0; height: 0; min-height: 220px; }
  .scopep > .ctrls, .scopep > table.meas, .scopep > .srcbox, .scopep > .row, .scopep > .hint { flex: none; }
  .mgrid { grid-template-columns: 1fr; }
  #resp { height: 220px; }
}
@media (min-width: 1500px) {
  .app { grid-template-columns: 400px minmax(0, 1fr) 400px; }
}
.grp.first { margin-top: 4px; }
.gsep { border: 0; border-top: 1px solid var(--line); margin: 14px 0 12px; }
