/* ESP32 Web Oscilloscope — styling. Two independent theme settings:
     html[data-body]   = everything outside the screen area (top bar, control panel)
     html[data-screen] = the screen area (status bar, waveform, channel chips, measurements)
   Themes change colours only, never layout or behaviour. Channel colours (--ch1…--ch4, --m1…--m4) belong to the
   screen theme and are used unchanged in the body, as coloured labels with contrasting ink, so they match in every
   combination. RUN / STOP / SINGLE colours are fixed. */

/* ---------------------------------------------------------------- body themes */
:root {  /* base values; the neutral bodies below override them */
  --bg: #0b0d0c; --panel: #121614; --panel2: #181e1b; --line: #26312b; --line2: #34423a; --text: #d9e3dc; --dim: #8a998f; --acc: #5ef08f; --warn: #ffb020; --err: #ff6b61; --on-bg: #2b4a37; --on-ink: #fff; --out-bg: #0e1210; --prim-bg: #1d3a29; --prim-line: #2f6b47; --sel-bg: #24302a; --toast: #1d2621; --shadow: rgba(0, 0, 0, .5);
  --body-scheme: dark;
}
/* neutral bodies: the standard dark greys without a tint; every control highlight is white, and only the brand
   label and the Connect button carry a colour (red or blue) */
[data-body="neutral-red"], [data-body="neutral-blue"] {
  --bg: #0c0c0c; --panel: #141414; --panel2: #1b1b1b; --line: #2b2b2b; --line2: #3b3b3b; --text: #e2e2e2; --dim: #969696; --acc: #ffffff; --warn: #ffb020; --err: #ff6b61; --on-bg: #4a4a4a; --on-ink: #fff; --out-bg: #101010; --prim-bg: #262626; --prim-line: #5c5c5c; --sel-bg: #2a2a2a; --toast: #222222; --shadow: rgba(0, 0, 0, .5);
  --body-scheme: dark;
}
[data-body="neutral-red"] { --brand: #ff3352; --brand-fill: #e90029; --brand-bg: #3a0911; }
[data-body="neutral-blue"] { --brand: #4d94ff; --brand-fill: #1f6fe5; --brand-bg: #0d2550; }
[data-body^="neutral"] .brand { color: var(--brand); }
[data-body^="neutral"] #btnConnect { background: var(--brand-bg); border-color: var(--brand-fill); }
[data-body^="neutral"] #btnConnect.on { background: var(--brand-fill); border-color: var(--brand-fill); color: #fff; }

/* ---------------------------------------------------------------- raised buttons
   Used by the neutral bodies. Every button in the top bar and the control panel gets a
   darker strip along its bottom edge (an inset shadow: the size and position of the button do not change).
   Excluded: the tab bar and the channel buttons (they keep their own underline), and Manual (a link).
     --rb-bg / --rb-sh        normal button: face / bottom strip
     --rb-on-bg/-ink/-sh      selected option in a segmented group: face / label / strip
     --rb-cn-sh / --rb-cn-on-sh  Connect button, not connected / connected: strip
   RUN, STOP and SINGLE keep their fixed colours, each with a darker strip of the same colour. */
[data-body^="neutral"] { --rb-bg: #2a2a2a; --rb-sh: #1b1b1b; --rb-on-bg: #ffffff; --rb-on-ink: #000000; --rb-on-sh: #9a9a9a; }
[data-body="neutral-red"] { --rb-cn-sh: #23080d; --rb-cn-on-sh: #8a0018; }
[data-body="neutral-blue"] { --rb-cn-sh: #091428; --rb-cn-on-sh: #103f87; }
/* Drawing: no visible border and no hover effect. The 1 px border stays but is transparent (so sizes do not change),
   and the face and its 3 px bottom strip are one background painted to the outer edge, so the strip follows the
   rounded corners. Each button only sets --rb-face / --rb-strip. Pressed: standard grey buttons take the
   selected-option look. Keyboard focus keeps its outline. */
[data-body^="neutral"] :is(#panel, #topbar) button:not(#tabBar button, #chTabs button, #measList button),
[data-body^="neutral"] :is(#panel, #topbar) button:not(#tabBar button, #chTabs button, #measList button):is(:hover, :disabled) { border-color: transparent; box-shadow: none;
  background: linear-gradient(to top, var(--rb-strip, var(--rb-sh)) 3px, var(--rb-face, var(--rb-bg)) 3px) border-box; }
[data-body^="neutral"] #panel .seg button.on { --rb-face: var(--rb-on-bg); --rb-strip: var(--rb-on-sh); color: var(--rb-on-ink); }
[data-body^="neutral"] .big.run { --rb-face: #2fd16c; --rb-strip: #1c8a44; }
[data-body^="neutral"] .big.stop { --rb-face: #ff4d4d; --rb-strip: #a82424; }
[data-body^="neutral"] .big.single { --rb-face: #ffa726; --rb-strip: #a86400; }
[data-body^="neutral"] #btnConnect { --rb-face: var(--brand-bg); --rb-strip: var(--rb-cn-sh); }
[data-body^="neutral"] #btnConnect.on { --rb-face: var(--brand-fill); --rb-strip: var(--rb-cn-on-sh); }
[data-body^="neutral"] :is(#panel, #topbar) button:not(#tabBar button, #chTabs button, #measList button):not(.big.run, .big.stop, .big.single, .primary, .on, #btnSingle):active:not(:disabled) {
  --rb-face: var(--rb-on-bg); --rb-strip: var(--rb-on-sh); color: var(--rb-on-ink); }
/* SINGLE lights up in its own armed colour while pressed */
[data-body^="neutral"] #btnSingle:active:not(:disabled) { --rb-face: #ffa726; --rb-strip: #a86400; color: #1a0e00; }
/* Segmented groups and steppers: no outline or dividers; the buttons sit 1 px apart, so the panel shows between them. */
[data-body^="neutral"] #panel :is(.seg, .stp) { border-color: transparent; gap: 1px; }
[data-body^="neutral"] #panel .seg button { border-right: 0; }
[data-body^="neutral"] #panel .stp output { min-width: 90px; padding-left: 7px; padding-right: 7px; }  /* gives back the 2 px of the two gaps */
/* No hover effects on the other controls either. */
[data-body^="neutral"] :is(#panel, #topbar) select:hover { border-color: var(--line2); }
[data-body^="neutral"] #topbar .btn:hover { border-color: var(--line2); }
[data-body^="neutral"] .tabbar button:not(.sel):hover { color: var(--dim); }

/* ---------------------------------------------------------------- screen themes */
:root, [data-screen="dark"] {
  --s-frame: #0b0d0c; --s-bg: #050706; --s-surf: #121614; --s-surf2: #181e1b; --s-line: #26312b; --s-line2: #34423a; --s-text: #d9e3dc; --s-dim: #8a998f; --s-acc: #5ef08f; --s-on: #2b4a37; --s-on-ink: #fff; --s-out: #0e1210; --s-sel: #24302a;
  --c-grid: #2a3530; --c-grid2: #1d2723; --c-axis: #33423a; --c-sep: #3d4d44; --c-label: #6f8077; --c-label2: #8a998f; --c-msg: #5d6d64; --c-fg: #e8e8e8; --c-cross: rgba(255, 255, 255, .25); --c-xy: #7dffb0;
  --ch1: #f7d038; --ch2: #36c8f4; --ch3: #ff5fcf; --ch4: #5fe07f; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8;
  --s-scheme: dark;
}
[data-screen="dark-blue"] {
  --s-frame: #0b0c0e; --s-bg: #050608; --s-surf: #13161a; --s-surf2: #191d22; --s-line: #262c33; --s-line2: #343c45; --s-text: #dbe1e8; --s-dim: #8b96a3; --s-acc: #5aa9ff; --s-on: #233f63; --s-on-ink: #fff; --s-out: #0e1115; --s-sel: #222a34;
  --c-grid: #283039; --c-grid2: #1b2128; --c-axis: #36404b; --c-sep: #414c58; --c-label: #75818e; --c-label2: #8b96a3; --c-msg: #5f6a77; --c-fg: #e8ecf0; --c-cross: rgba(255, 255, 255, .25); --c-xy: #8fc8ff;
  --ch1: #f7d038; --ch2: #36c8f4; --ch3: #ff5fcf; --ch4: #5fe07f; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8;
  --s-scheme: dark;
}
[data-screen="dark-amber"] {
  --s-frame: #0d0c0a; --s-bg: #070605; --s-surf: #161412; --s-surf2: #1d1a17; --s-line: #2e2924; --s-line2: #3f3830; --s-text: #e8e0d6; --s-dim: #9e9385; --s-acc: #ffb547; --s-on: #4d3a1c; --s-on-ink: #fff; --s-out: #11100d; --s-sel: #2c261f;
  --c-grid: #332d26; --c-grid2: #231f1a; --c-axis: #433b32; --c-sep: #4f463b; --c-label: #857a6c; --c-label2: #9e9385; --c-msg: #6c6255; --c-fg: #f0e8de; --c-cross: rgba(255, 255, 255, .25); --c-xy: #ffd27a;
  --ch1: #f7d038; --ch2: #36c8f4; --ch3: #ff5fcf; --ch4: #5fe07f; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8;
  --s-scheme: dark;
}
[data-screen="neutral-red"], [data-screen="neutral-blue"] {
  --s-frame: #0c0c0c; --s-bg: #060606; --s-surf: #141414; --s-surf2: #1b1b1b; --s-line: #2b2b2b; --s-line2: #3b3b3b; --s-text: #e2e2e2; --s-dim: #969696; --s-acc: #ffffff; --s-on: #4a4a4a; --s-on-ink: #fff; --s-out: #101010; --s-sel: #2a2a2a;
  --c-grid: #303030; --c-grid2: #202020; --c-axis: #424242; --c-sep: #4c4c4c; --c-label: #7c7c7c; --c-label2: #969696; --c-msg: #666666; --c-fg: #ececec; --c-cross: rgba(255, 255, 255, .25); --c-xy: #e8e8e8;
  --s-scheme: dark;
}
/* channel colours: red set yellow / green / blue / red, blue set the standard yellow / cyan / magenta / green */
[data-screen="neutral-red"] { --ch1: #f7d038; --ch2: #3ee06a; --ch3: #4f8dff; --ch4: #ff4f64; --m1: #b48cff; --m2: #ff9f43; --m3: #4fe0d0; --m4: #e8e8e8; }
[data-screen="neutral-blue"] { --ch1: #f7d038; --ch2: #36c8f4; --ch3: #ff5fcf; --ch4: #5fe07f; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8; }
[data-screen="light"] {
  --s-frame: #e6e8e4; --s-bg: #fdfdfb; --s-surf: #ffffff; --s-surf2: #f2f4f1; --s-line: #d3d8d2; --s-line2: #b4bcb3; --s-text: #1b231d; --s-dim: #5b675e; --s-acc: #12803f; --s-on: #cdeedb; --s-on-ink: #0b3d20; --s-out: #f4f6f3; --s-sel: #e3ebe5;
  --c-grid: #d6dbd4; --c-grid2: #e7eae5; --c-axis: #aab2a8; --c-sep: #9aa398; --c-label: #737e75; --c-label2: #5b675e; --c-msg: #8a948c; --c-fg: #222a24; --c-cross: rgba(0, 0, 0, .25); --c-xy: #0b7a3b;
  --ch1: #a87400; --ch2: #0070b0; --ch3: #c2187a; --ch4: #1d8a38; --m1: #6a3fc7; --m2: #c25500; --m3: #c62828; --m4: #333a35;
  --s-scheme: light;
}
[data-screen="light-blue"] {
  --s-frame: #e4e8ed; --s-bg: #fcfdfe; --s-surf: #ffffff; --s-surf2: #f1f4f7; --s-line: #d2d9e0; --s-line2: #b3bdc8; --s-text: #161c23; --s-dim: #536070; --s-acc: #1565c0; --s-on: #d3e4f8; --s-on-ink: #0b3566; --s-out: #f3f6f9; --s-sel: #e0e8f1;
  --c-grid: #d5dce4; --c-grid2: #e6ebf0; --c-axis: #a9b4c0; --c-sep: #98a4b1; --c-label: #6f7c8a; --c-label2: #536070; --c-msg: #8893a0; --c-fg: #1d242c; --c-cross: rgba(0, 0, 0, .25); --c-xy: #0d5fb0;
  --ch1: #a87400; --ch2: #0070b0; --ch3: #c2187a; --ch4: #1d8a38; --m1: #6a3fc7; --m2: #c25500; --m3: #c62828; --m4: #333a35;
  --s-scheme: light;
}
[data-screen="light-amber"] {
  --s-frame: #ebe6df; --s-bg: #fefdfb; --s-surf: #ffffff; --s-surf2: #f6f2ec; --s-line: #ddd5ca; --s-line2: #c2b6a6; --s-text: #221c14; --s-dim: #64584a; --s-acc: #b35c00; --s-on: #f6dfc0; --s-on-ink: #4d2700; --s-out: #f8f4ee; --s-sel: #efe6da;
  --c-grid: #e0d8cd; --c-grid2: #ece6dd; --c-axis: #bcae9c; --c-sep: #ab9d8a; --c-label: #827562; --c-label2: #64584a; --c-msg: #9a8e7e; --c-fg: #2a231a; --c-cross: rgba(0, 0, 0, .25); --c-xy: #a35400;
  --ch1: #a87400; --ch2: #0070b0; --ch3: #c2187a; --ch4: #1d8a38; --m1: #6a3fc7; --m2: #c25500; --m3: #c62828; --m4: #333a35;
  --s-scheme: light;
}
[data-screen="midnight"] {
  --s-frame: #0a0f1e; --s-bg: #070b18; --s-surf: #10172a; --s-surf2: #16203a; --s-line: #22304f; --s-line2: #2f4168; --s-text: #dbe4f5; --s-dim: #8c9bbb; --s-acc: #6fb2ff; --s-on: #24406e; --s-on-ink: #fff; --s-out: #0b1122; --s-sel: #1d2a47;
  --c-grid: #1f2d4d; --c-grid2: #152038; --c-axis: #2c3e66; --c-sep: #36497a; --c-label: #6d80a8; --c-label2: #8c9bbb; --c-msg: #55678f; --c-fg: #eef3ff; --c-cross: rgba(255, 255, 255, .25); --c-xy: #8fd0ff;
  --ch1: #ffe14d; --ch2: #ff6fb5; --ch3: #4fd8ff; --ch4: #7ee06f; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8;
  --s-scheme: dark;
}
[data-screen="graphite"] {
  --s-frame: #141920; --s-bg: #0d1218; --s-surf: #19202a; --s-surf2: #202935; --s-line: #2b3644; --s-line2: #3a4859; --s-text: #dbe3ec; --s-dim: #8b9aab; --s-acc: #4fb3ff; --s-on: #24496b; --s-on-ink: #fff; --s-out: #0f151c; --s-sel: #26313f;
  --c-grid: #2a3646; --c-grid2: #1c2633; --c-axis: #3a4a5e; --c-sep: #44566c; --c-label: #71839a; --c-label2: #8b9aab; --c-msg: #5f7187; --c-fg: #eef3f8; --c-cross: rgba(255, 255, 255, .25); --c-xy: #8fd0ff;
  --ch1: #f5d33f; --ch2: #4cd964; --ch3: #5aa2ff; --ch4: #ff6fae; --m1: #b48cff; --m2: #ff9f43; --m3: #ff6b6b; --m4: #e8e8e8;
  --s-scheme: dark;
}
[data-screen="phosphor"] {
  --s-frame: #040a06; --s-bg: #020904; --s-surf: #0a140d; --s-surf2: #0f1d13; --s-line: #173322; --s-line2: #22492f; --s-text: #b8f5c6; --s-dim: #5f9a70; --s-acc: #5ef08f; --s-on: #1d4a2c; --s-on-ink: #e6ffec; --s-out: #061009; --s-sel: #143222;
  --c-grid: #164428; --c-grid2: #0d2c19; --c-axis: #22603a; --c-sep: #2a6e43; --c-label: #46905f; --c-label2: #63a275; --c-msg: #2f7048; --c-fg: #d2ffdc; --c-cross: rgba(160, 255, 190, .3); --c-xy: #8dffad;
  --ch1: #a6ff8f; --ch2: #ffd75e; --ch3: #6fd3ff; --ch4: #ff8fd0; --m1: #c7a6ff; --m2: #ffa95e; --m3: #ff7a7a; --m4: #e6fff0;
  --s-scheme: dark;
}
[data-screen="amber"] {
  --s-frame: #0b0600; --s-bg: #080400; --s-surf: #140c02; --s-surf2: #1c1204; --s-line: #33220a; --s-line2: #4a320f; --s-text: #ffd9a0; --s-dim: #b08850; --s-acc: #ffb000; --s-on: #4a3208; --s-on-ink: #fff3dc; --s-out: #0f0902; --s-sel: #2a1c06;
  --c-grid: #3a2808; --c-grid2: #241804; --c-axis: #56400f; --c-sep: #6a4c14; --c-label: #a07a3c; --c-label2: #c09050; --c-msg: #7a5a28; --c-fg: #ffe6bf; --c-cross: rgba(255, 200, 120, .3); --c-xy: #ffc04d;
  --ch1: #ffb000; --ch2: #fff0b8; --ch3: #ff6a2a; --ch4: #c6e86a; --m1: #e8a0ff; --m2: #ff9248; --m3: #8fd8ff; --m4: #ffe6bf;
  --s-scheme: dark;
}
[data-screen="lcd"] {
  --s-frame: #9aa58e; --s-bg: #c5cfb6; --s-surf: #d3dcc6; --s-surf2: #dde5d2; --s-line: #a9b49a; --s-line2: #8e9a80; --s-text: #1e2618; --s-dim: #4b5642; --s-acc: #2f4f1f; --s-on: #a9bc92; --s-on-ink: #1e2618; --s-out: #cfd8c1; --s-sel: #b9c6a8;
  --c-grid: #a6b296; --c-grid2: #b6c1a7; --c-axis: #7f8b72; --c-sep: #6f7b62; --c-label: #505b45; --c-label2: #3d4734; --c-msg: #6a7560; --c-fg: #1e2618; --c-cross: rgba(0, 0, 0, .3); --c-xy: #1f3a12;
  --ch1: #4a3a00; --ch2: #0b3d73; --ch3: #6e0d4f; --ch4: #135c1c; --m1: #4b2a8a; --m2: #7a3a00; --m3: #8a1010; --m4: #222a1e;
  --s-scheme: light;
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; }
html { color-scheme: var(--body-scheme); }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif; overflow: hidden; }
#app { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
button, select, input, textarea, .btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line2); border-radius: 5px;
}
button, .btn { padding: 4px 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: 28px; }
button:hover, .btn:hover, select:hover { border-color: var(--acc); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, canvas:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
button:disabled { opacity: .45; cursor: default; border-color: var(--line2); }
select { padding: 3px 6px; min-height: 28px; }
input[type=text], input[type=number], input:not([type]) { padding: 4px 6px; min-height: 28px; }
textarea { width: 100%; padding: 6px; font: 12px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; resize: vertical; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace; }
code { color: var(--acc); }
a { color: var(--acc); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.err { color: var(--err); font-size: 12px; white-space: pre-wrap; }
.spacer { flex: 1; }
.primary { background: var(--prim-bg); border-color: var(--prim-line); }
.primary.on { background: var(--acc); color: var(--bg); border-color: var(--acc); }
.hidden { display: none !important; }
.dimmed { opacity: .45; }

header#topbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; color: var(--acc); margin-right: 6px; font-size: 15px; }
.brand b { color: var(--dim); }
.lbl { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); }
#connInfo { font-size: 12px; }

main { display: grid; grid-template-columns: minmax(0, 1fr) 6px var(--panelW, 360px); min-height: 0; }
#splitter { cursor: col-resize; background: var(--line); touch-action: none; }
#splitter:hover, #splitter.drag { background: var(--acc); }

/* ---------------------------------------------------------------- screen area */
#scopeArea {
  /* the screen area uses the theme's screen surfaces */
  --bg: var(--s-bg); --panel: var(--s-surf); --panel2: var(--s-surf2); --line: var(--s-line); --line2: var(--s-line2);
  --text: var(--s-text); --dim: var(--s-dim); --acc: var(--s-acc); --on-bg: var(--s-on); --on-ink: var(--s-on-ink);
  --out-bg: var(--s-out); --sel-bg: var(--s-sel);
  color: var(--text); background: var(--s-frame); color-scheme: var(--s-scheme);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 6px; padding: 6px; min-height: 0;
}
#statusBar { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12px; }
.sb i { font-style: normal; color: var(--dim); margin-right: 5px; }
.sb b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calflag { font-size: 10px; font-weight: 700; padding: 0 5px; border: 1px solid var(--line2); border-radius: 3px; color: var(--acc); }
.badge { padding: 1px 8px; border-radius: 4px; font-weight: 700; font-size: 12px; background: var(--panel2); border: 1px solid var(--line2); }
.badge.run { background: #2fd16c; color: #031208; border-color: #2fd16c; }
.badge.stop { background: #ff4d4d; color: #fff; border-color: #ff4d4d; }
.badge.single { background: #ffa726; color: #1a0e00; border-color: #ffa726; }
.badge.roll { background: #2d7ff9; color: #fff; border-color: #2d7ff9; }
.badge.trig { color: var(--acc); border-color: var(--acc); }
.badge.wait { color: #e09400; border-color: #b07a10; }
.badge.acq { min-width: 3.4em; text-align: center; }
.badge.off { opacity: .45; }

#screen { position: relative; background: var(--s-bg); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; min-height: 260px; }
#screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cvOver { cursor: crosshair; touch-action: none; }
#hint { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); font-size: 11px; color: var(--dim); background: var(--panel); border: 1px solid var(--line);
  padding: 2px 10px; border-radius: 4px; pointer-events: none; white-space: nowrap; max-width: 96%; overflow: hidden; text-overflow: ellipsis; opacity: .92; }
#curBox { position: absolute; right: 8px; top: 8px; background: var(--panel); opacity: .92; border: 1px solid var(--line2); border-radius: 5px; padding: 6px 8px;
  font: 12px/1.45 ui-monospace, Consolas, monospace; pointer-events: none; white-space: pre; }

#chanBar { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 3px 9px; border-radius: 5px; border: 1px solid var(--line2); background: var(--panel); cursor: pointer;
  font-size: 12px; font-variant-numeric: tabular-nums; user-select: none; }
.chip .nm { font-weight: 700; padding: 0 5px; border-radius: 3px; }
.chip.off { opacity: .45; }
.chip.sel { border-color: var(--text); }
.chip .flag { display: inline-block; box-sizing: border-box; width: 46px; padding: 0 4px; text-align: center; font-size: 11px; }
.chip .clip { color: #fff; background: #d93025; padding: 0 5px; border-radius: 3px; }
.chip .floor { color: var(--dim); font-size: 11px; font-style: italic; }
#measBar { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 8px; font-size: 12px; }
#measBar.stats { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.mcell { background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; font-variant-numeric: tabular-nums; }
.mcell .h { color: var(--dim); }
.mcell .v { font-weight: 600; float: right; }
.mcell .s { display: block; color: var(--dim); font-size: 11px; clear: both; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcell .s i { font-style: normal; opacity: .7; margin: 0 2px 0 8px; }
.mcell .s i:first-child { margin-left: 0; }

/* ---------------------------------------------------------------- control panel */
#panel { overflow: auto; background: var(--panel); padding: 8px 10px 24px; }
.runrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.big { min-height: 40px; font-weight: 700; letter-spacing: .03em; }
.big.run { background: #2fd16c; color: #031208; border-color: #2fd16c; }
.big.stop { background: #ff4d4d; color: #fff; border-color: #ff4d4d; }
.big.single { background: #ffa726; color: #1a0e00; border-color: #ffa726; }

.tabbar { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line2); margin-bottom: 4px; }
.tabbar button { border: 1px solid transparent; border-bottom: 0; border-radius: 5px 5px 0 0; background: transparent; color: var(--dim); min-height: 28px; padding: 3px 5px; font-size: 12px; font-weight: 600; flex: 1 1 auto; }
.tabbar button:hover { color: var(--text); border-color: transparent; }
.tabbar button.sel { background: var(--panel2); color: var(--text); border-color: var(--line2); margin-bottom: -1px; }
.pane { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 0 18px; align-items: start; }
.pane[hidden] { display: none; }
.row[hidden] { display: none; }
.grp { padding: 6px 0 8px; }
.grp h4 { margin: 2px 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--line); min-height: 22px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--dim); display: flex; align-items: center; gap: 8px; }
.grp h4 .note { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); }
.grp h4 .right { margin-left: auto; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 5px 0; }
.k { color: var(--dim); min-width: 74px; }
.k.r { min-width: 0; margin-left: 4px; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--acc); }
.sm { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.grow { flex: 1; }
.w4 { width: 4.5em; } .w6 { width: 6.5em; } .w8 { width: 8.5em; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 5px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line2); background: var(--panel2); min-height: 28px; padding: 3px 9px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--on-bg); color: var(--on-ink); box-shadow: inset 0 -2px 0 var(--acc); }
.stp { display: inline-flex; align-items: stretch; border: 1px solid var(--line2); border-radius: 5px; overflow: hidden; }
.stp button { border: 0; border-radius: 0; min-width: 30px; font-size: 16px; padding: 0; background: var(--panel2); }
.stp output { min-width: 92px; padding: 4px 8px; text-align: center; font-variant-numeric: tabular-nums; background: var(--out-bg); cursor: ns-resize; user-select: none; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.tabs button { min-height: 26px; padding: 2px 9px; font-weight: 700; font-size: 12px; border-bottom-width: 3px; }
.tabs button.sel { background: var(--sel-bg); }
.tabs button.offc { opacity: .55; }
.cbadge { padding: 0 5px; border-radius: 3px; }
.mathShared { margin-top: 6px; }
#measList { display: flex; flex-wrap: wrap; gap: 4px; }
#measList span { background: var(--panel2); border: 1px solid var(--line2); border-radius: 4px; padding: 1px 4px 1px 4px; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
#measList button { min-height: 20px; padding: 0 5px; border: 0; background: transparent; color: var(--dim); }
#curRead { white-space: pre; margin-top: 4px; }
.calgrid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 4px 6px; align-items: center; max-width: 300px; margin: 4px 0; }
.calgrid input { width: 100%; }
#log { color: var(--dim); max-height: 160px; overflow: auto; white-space: pre-wrap; }
#toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--toast); color: var(--text); border: 1px solid var(--line2); border-radius: 6px; padding: 8px 14px;
  max-width: min(92vw, 640px); box-shadow: 0 6px 24px var(--shadow); z-index: 10; }
#toast.err { border-color: var(--err); }

@media (max-width: 980px) {
  body { overflow: auto; }
  #app { height: auto; }
  main { grid-template-columns: 1fr; }
  #splitter { display: none; }
  #scopeArea { grid-template-rows: auto 60vh auto auto; }
  #panel { overflow: visible; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
