/* Libressi styles */
:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --border: #e2e7ef;
  --border-strong: #cfd6e2;
  --text: #1b2333;
  --muted: #667085;
  --accent: #2f5bd3;
  --accent-rgb: 47, 91, 211;       /* for rgba(): Chrome does not animate colour functions inside filters */
  --accent-hover: #2549b0;
  --accent-soft: #e9effd;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --cm-keyword: #8250df; --cm-number: #b5420e; --cm-string: #8a5b00; --cm-comment: #6e7781;   /* Python, as in Brygame Studio */
  --danger-soft: #fdecec;
  --calc-bg: #f4f1fd;
  --calc-head: #6741d9;
  --grid-line: #edf0f5;
  --axis: #9aa4b5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-pop: 0 10px 30px rgba(16, 24, 40, .16), 0 2px 6px rgba(16, 24, 40, .08);
  --radius: 10px;
  --bar: 30px;                          /* a reading's height, the acquisition bar's tallest */
  --row: calc(13px * 1.4 + 12px);       /* a field's height */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Roboto Mono", "DejaVu Sans Mono", monospace;
  color-scheme: light;
}
:root.dark-theme {
  --bg: #0f131a;
  --panel: #171c25;
  --panel-2: #1c2230;
  --border: #2a3242;
  --border-strong: #38425a;
  --text: #e6e9ef;
  --muted: #98a2b3;
  --accent: #6d8ff0;
  --accent-rgb: 109, 143, 240;
  --accent-hover: #87a3f5;
  --accent-soft: #233056;
  --accent-text: #0f131a;
  --danger: #ff8787;
  --cm-keyword: #c792ea; --cm-number: #f78c6c; --cm-string: #e5c07b; --cm-comment: #5b6b7a;
  --danger-soft: #3a1f24;
  --calc-bg: #211d33;
  --calc-head: #b197fc;
  --grid-line: #232a38;
  --axis: #566179;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { scrollbar-color: rgba(var(--accent-rgb), .3) transparent; }   /* light blue, in both themes */
body {
  margin: 0;
  font: 14px/1.4 var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
input[list]::-webkit-calendar-picker-indicator { display: none !important; }   /* the units drop down on a click, no arrow eating the narrow fields */
code, kbd { font-family: var(--mono); font-size: .92em; }
code { background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  flex: none;
  height: 55px;                 /* 54 px inside the border: the 28 px logo sits on whole pixels (no Firefox jitter) */
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-logo { display: block; line-height: 0; }
.brand-logo img {
  display: block; transition: transform .2s, filter .2s;
  filter: drop-shadow(0 0 4px rgba(var(--accent-rgb), 0)) drop-shadow(0 0 10px rgba(var(--accent-rgb), 0));
}
.brand-logo:hover img {
  transform: scale(1.06);
  filter: drop-shadow(0 0 4px rgba(var(--accent-rgb), .9)) drop-shadow(0 0 10px rgba(var(--accent-rgb), .5));
}
.doc-title {
  min-width: 0;
  flex: 0 1 340px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 15px;
  color: var(--muted);
}
@supports (field-sizing: content) {   /* the field fits the title, the example icon follows it */
  .doc-title { field-sizing: content; flex: 0 1 auto; max-width: 340px; min-width: 4em; }
}
.doc-title:hover { border-color: var(--border); }
.doc-title:focus { outline: none; border-color: var(--accent); color: var(--text); background: var(--panel); }
.actions { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.tb {
  display: flex; align-items: center; gap: 6px;
  border: 0; background: transparent; border-radius: 7px;
  padding: 7px 10px; cursor: pointer; color: var(--text);
}
.tb:hover, .tb[aria-expanded="true"] { background: var(--panel-2); }
.tb svg, .icon-btn svg, #moreMenu svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tb svg, #moreMenu svg { color: var(--muted); }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; flex: none; }
.theme-toggle { width: 38px; justify-content: center; color: var(--muted); }

/* ---------- layout ---------- */
.layout {
  --split: 12px;                /* the band of the splitters, the gap of the rest of the page */
  --table-min: 270px;           /* the table bar fully folded, with « ± » */
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(var(--table-min), var(--table-fr, 1fr)) var(--split) minmax(320px, var(--right-fr, 2fr));   /* 1/3, 2/3 */
  padding: 12px;
}
.layout:has(#btnShowU[hidden]) { --table-min: 230px; }
.right { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
/* the same splitters as Bricks: a band with a grip in the middle, dragged to share the place */
.splitter { flex: none; display: grid; place-items: center; cursor: col-resize; touch-action: none; }
.splitter.rows { height: var(--split); cursor: row-resize; }
.splitter::before {
  content: ""; width: 4px; height: 44px; border-radius: 2px;
  background: var(--border-strong); transition: background-color .15s ease;
}
.splitter.rows::before { width: 44px; height: 4px; }
.splitter:hover::before, .splitter:focus-visible::before, .splitter--active::before { background: var(--muted); }
.splitter:focus-visible { outline: none; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 14px; margin: 0; font-weight: 650; }
.panel-head h3 { font-size: 13px; margin: 0; font-weight: 650; }
.panel-head.sub { border-bottom: 0; padding: 8px 12px 4px; }
.graph-panel { flex: 1 1 auto; min-height: 280px; }
/* never below the one-line acquisition, which takes its place: its bar and its row, with their paddings and borders */
.model-panel { flex: 0 1 auto; max-height: 40%; min-height: calc(var(--bar) + var(--row) + 43px); }
@media (min-width: 861px) {
  .right.split .model-panel { flex: none; height: calc((100% - var(--split)) * var(--model-share)); max-height: none; }   /* moved by its splitter */
  /* the acquisition on one line has nothing to share: its own height, the band without its grip */
  .right.split:has(#acqView:not([hidden]) .acq-python[hidden]) .model-panel { flex: 0 1 auto; height: auto; max-height: 40%; }
}
.right:has(#acqView:not([hidden]) .acq-python[hidden]) #splitModel { visibility: hidden; }
/* the Python program is an editor: it takes the graph's place too */
.right:has(#acqView:not([hidden]) .acq-python:not([hidden])) :is(.graph-panel, #splitModel) { display: none; }
.right:has(#acqView:not([hidden]) .acq-python:not([hidden])) .model-panel { flex: 1 1 auto; height: auto; max-height: none; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 550;
}
.btn:hover { background: var(--panel-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.action { border-color: var(--text); font-weight: 650; }   /* the main screen's actions: blue means selected */
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.action.danger { border-color: var(--danger); }   /* Arrêter, while a measurement or a program runs */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:not(:disabled):hover { background: var(--panel-2); color: var(--text); }
.icon-btn:not(:disabled):has(use[href="#i-trash"]):hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }
button:focus-visible, select:focus-visible, .toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- table ---------- */
.table-panel { overflow: hidden; container: table / inline-size; }
/* as the table narrows: « ± » alone, then both « + » together, before the parameters bar would wrap
   (widths measured with Noto Sans) */
@container table (width < 411px) { #btnShowU span { display: none; } }
@container table (width < 380px) { :is(#btnAddCol, #btnAddParam) span { display: none; } }
@container model (width < 380px) { #btnAddModel span { display: none; } }   /* on one column, under the other two */
.table-wrap { flex: 1; overflow: auto; min-height: 120px; }
.grid { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--grid-line); border-right: 1px solid var(--grid-line); padding: 0; height: 30px; }
.grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  text-align: left;
  vertical-align: bottom;
}
.grid th.colhead { padding: 6px 22px 5px 10px; cursor: pointer; user-select: none; }
.grid th.colhead:hover { background: var(--accent-soft); }
.grid th.colhead .cname { display: block; font-size: 14px; white-space: nowrap; }
.grid th.colhead .cunit { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); }
.grid th.colhead .sort {
  position: absolute; top: 3px; right: 3px; padding: 3px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 9px; line-height: 1; opacity: .6;
}
.grid th.colhead .sort:hover { color: var(--accent); opacity: 1; }
.grid th.colhead.calc .cname { color: var(--calc-head); }
.grid th.colhead.calc .cname::after { content: " ƒ"; font-weight: 400; font-style: italic; opacity: .7; }
.grid th.colhead.err .cname { color: var(--danger); }
/* « ! » badges and check mark drawn in CSS: the ⚠ and ✓ characters are missing from some fonts */
.grid th.colhead.err .cname::after, .model-err::before, .model-warn::before {
  content: "!"; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; background: var(--danger); color: #fff;
  font: 800 11px/1 var(--font); font-style: normal; vertical-align: 1px;
}
.grid th.colhead.err .cname::after { margin-left: 5px; }
.model-err::before, .model-warn::before { margin-right: 6px; }
.model-warn::before { background: #b08800; }
.grid .rn {
  width: 40px; min-width: 40px;
  text-align: right; padding: 0 8px;
  color: var(--muted); font-size: 12px;
  background: var(--panel-2);
  position: sticky; left: 0; z-index: 1;
}
.grid thead .rn { z-index: 3; }
.grid td.rn { position: sticky; }
.grid .rn .add-row, .grid .rn .del-row {
  display: none; border: 0; background: transparent;
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 1px;
}
.grid .rn .add-row { color: var(--accent); }
.grid .rn .del-row { color: var(--danger); }
.grid td.rn:hover span { display: none; }
.grid td.rn:hover .add-row, .grid td.rn:hover .del-row { display: inline; }
.grid .cell {
  width: 100%; height: 29px;
  border: 0; background: transparent;
  padding: 0 10px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.grid .cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--panel); }
.grid .cell.bad { color: var(--danger); background: var(--danger-soft); }
.grid td.calc { background: var(--calc-bg); text-align: right; padding: 0 10px; color: var(--text); white-space: nowrap; }
.grid tr.phantom .cell::placeholder { color: var(--muted); }
.grid tr.phantom td { background: transparent; }
.grid tr > :last-child { border-right: 0; }

/* ---------- parameters ---------- */
.params { flex: none; border-top: 1px solid var(--border); padding-bottom: 8px; max-height: 35%; overflow: auto; }
.param-list { padding: 2px 12px; display: flex; flex-direction: column; gap: 4px; }
.param { display: flex; align-items: center; gap: 6px; }
.param input {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  padding: 3px 7px; min-width: 0;
}
.param input:focus { outline: none; border-color: var(--accent); }
.param .p-name { width: 70px; font-weight: 600; }
.param .p-value { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.param .p-value.bad { border-color: var(--danger); color: var(--danger); }
.param .p-unit { width: 64px; color: var(--muted); }
.param .eq { color: var(--muted); }

/* ---------- plot ---------- */
.graph-controls { gap: 8px 12px; flex-wrap: nowrap; overflow: hidden; }   /* its one-line trial (app.js) must not widen the page: a phone would zoom out and lose its scroll */
.sel { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.sel select {
  border: 1px solid var(--border-strong); border-radius: 7px; background: var(--panel);
  padding: 4px 8px; font-weight: 600; color: var(--text);
}
.chips { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.chips-label { color: var(--muted); font-size: 13px; margin-right: 2px; }
.chip {
  --c: var(--accent);
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--panel); padding: 2px 10px 2px 8px; cursor: pointer;
  font-size: 13px; font-weight: 550; color: var(--muted);
}
.chip i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--c); }
.chip.on { color: var(--text); border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, var(--panel)); }
.chip.on i { background: var(--c); }
.toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); margin: 0; }
.plot-wrap { position: relative; flex: 1; min-height: 0; }
/* a finger moving up or down scrolls the page (the graph fills the middle of a phone), sideways it stays the graph's */
.plot-wrap canvas { position: absolute; inset: 0; display: block; touch-action: pan-y; cursor: crosshair; border-radius: 0 0 var(--radius) var(--radius); }
.plot-wrap canvas.picking { cursor: ew-resize; }
.plot-wrap canvas.grab { cursor: grab; }
.plot-wrap:has(#plotEmpty:not([hidden])) canvas { cursor: default; }
.plot-hint {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 4;
  background: var(--text); color: var(--panel); border-radius: 8px; padding: 6px 12px;
  font-size: 13px; pointer-events: none; box-shadow: var(--shadow-pop); max-width: calc(100% - 24px); text-align: center;
}
.plot-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); padding: 24px; text-align: center; pointer-events: none;
}
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--text); color: var(--panel);
  border-radius: 7px; padding: 6px 9px; font-size: 12.5px; line-height: 1.45;
  box-shadow: var(--shadow-pop); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tooltip .tip-head { opacity: .65; font-size: 11.5px; }
.tooltip .tip-foot { opacity: .6; font-size: 11px; margin-top: 3px; }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }


/* ---------- uncertainties and statistics ---------- */
.grid th.uhead { padding-right: 10px; }
.grid th.uhead .cname { color: var(--muted); font-weight: 500; font-size: 13px; }
.grid td.ucell { text-align: right; padding: 0 10px; color: var(--muted); font-size: 12.5px; white-space: nowrap; background: var(--panel-2); }
#btnShowU[aria-pressed="false"] { color: var(--muted); }
.tabs { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; gap: 2px; }
.tab { border: 0; background: transparent; border-radius: 6px; padding: 3px 8px; font-size: 12.5px; font-weight: 550; color: var(--muted); cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.tab:disabled { cursor: default; }
.tab:disabled:not([aria-selected="true"]) { opacity: .5; }
.graph-tools { display: flex; align-items: center; gap: 8px 12px; flex: 1 0 auto; }
.tool-group { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.tool-icons { display: flex; align-items: center; gap: 10px; }
/* too narrow for one line (app.js): the tabs and the options first, the axes or the quantities below */
.graph-controls.stacked { flex-wrap: wrap; }
.graph-controls.stacked .tool-group { order: 1; flex-wrap: wrap; justify-content: flex-end; row-gap: 8px; }
.graph-controls.stacked :is(#graphTools, #statTools) { order: 2; flex: 1 1 100%; flex-wrap: wrap; min-width: 0; }
.stats-view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.stats-cards { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-card { border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); padding: 6px 12px; min-width: 110px; }
.stat-card .k { font-size: 12px; color: var(--muted); }
.stat-card .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-card.main { border-color: var(--accent); background: var(--accent-soft); }
.hist-wrap { position: relative; flex: 1; min-height: 140px; }
.hist-wrap canvas { position: absolute; inset: 0; display: block; }
#statRef, .cmp input, .cmp select {
  border: 1px solid var(--border-strong); background: var(--panel); border-radius: 7px; padding: 4px 8px; color: var(--text);
}
#statRef { width: 110px; text-align: right; }
#statOptions, .stat-z { white-space: nowrap; }
/* its room is kept while empty: typing a reference never moves the bar */
.stat-z { font-size: 13px; min-width: 170px; min-height: 1lh; text-align: right; }
.stat-z.ok, .cmp-z.ok { color: #2f9e44; font-weight: 600; }
.stat-z.ko, .cmp-z.ko { color: var(--danger); font-weight: 600; }
.cmp { display: flex; align-items: center; gap: 6px 8px; flex-wrap: wrap; margin-top: 6px; font-size: 13px; color: var(--muted); }
.cmp input { width: 100px; text-align: right; }
.model-warn { color: #b08800; }
.u-field { margin-top: 14px; }
.u-field > label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); font-weight: 550; }
.u-calc-note { display: none; margin: 14px 0 0; }
form.is-calc .u-field { display: none; }
form.is-calc .u-calc-note { display: block; }
.param .pm { color: var(--muted); }
.param .p-u { width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.param .p-u.bad { border-color: var(--danger); color: var(--danger); }

/* ---------- modelling ---------- */
.model-list { overflow: auto; padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
/* empty, the bar and the row of the one-line acquisition, which takes its place without a jump */
.model-panel:has(.empty-models) #modelHead h2 { line-height: var(--bar); }
.model-list:has(> .empty-models) { padding-block: 10px; }
.empty-models { color: var(--muted); padding: 0 2px; min-height: var(--row); display: flex; align-items: center; }
.model-card { border: 1px solid var(--border); border-radius: 9px; padding: 8px 8px 8px 10px; background: var(--panel-2); }
.model-row { display: flex; align-items: center; gap: 8px; }
.swatch { flex: none; width: 4px; align-self: stretch; border-radius: 4px; background: var(--c, var(--accent)); }
.model-card[data-dash="1"] .swatch { background: repeating-linear-gradient(to bottom, var(--c) 0 7px, transparent 7px 11px); }
.model-card[data-dash="2"] .swatch { background: repeating-linear-gradient(to bottom, var(--c) 0 2px, transparent 2px 5px); }
.model-card[data-dash="3"] .swatch { background: repeating-linear-gradient(to bottom, var(--c) 0 8px, transparent 8px 11px, var(--c) 11px 13px, transparent 13px 16px); }
.model-expr {
  flex: 1; min-width: 0;
  border: 1px solid var(--border); background: var(--panel); border-radius: 7px;
  padding: 6px 9px; font-family: var(--mono); font-size: 14px;
}
.model-expr:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.model-res { margin: 8px 0 0 12px; }
.model-inters { display: flex; flex-direction: column; gap: 8px; }
.model-inters:empty, .tan-result:empty { display: none; }
.model-card.inter .stats { margin: 0 0 4px; }
.model-res:empty { display: none; }
.pchips { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.pchip { font-variant-numeric: tabular-nums; font-size: 15px; }
.pchip .pname { font-weight: 650; font-style: italic; font-family: Georgia, "Times New Roman", serif; font-size: 16px; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; color: var(--muted); font-size: 12.5px; align-items: center; }
.model-err { color: var(--danger); font-size: 13px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- menus ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  min-width: 280px; max-height: 70vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-pop); padding: 6px;
}
.menu-right { left: auto; right: 0; }
.menu.up { top: auto; bottom: calc(100% + 6px); }
.menu-title { font-size: 12px; color: var(--muted); padding: 4px 8px 6px; }
.menu-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%;
  border: 0; background: transparent; text-align: left; padding: 7px 9px; border-radius: 7px; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); outline: none; }
.menu-item .mi-label { font-weight: 600; }
.menu-item .mi-sub { font-size: 12.5px; color: var(--muted); }
.menu-item .mi-formula { font-size: 13px; color: var(--muted); font-family: Georgia, "Times New Roman", serif; font-style: italic; }
#examplesMenu { min-width: 400px; }
.menu-item.with-icon { flex-direction: row; align-items: center; gap: 12px; }
.mi-text { display: flex; flex-direction: column; gap: 1px; }
.mi-icon { flex: none; width: 30px; height: 30px; padding: 4px; border-radius: 8px; background: var(--accent-soft); color: var(--accent);
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.doc-icon { flex: none; margin-left: -6px; }
.brand + .doc-btn { margin-left: 0; }
.doc-icon > button { display: block; border: 0; padding: 0; background: none; cursor: pointer; border-radius: 8px; }
.doc-icon > button .mi-icon { display: block; }
.doc-btn { flex: none; width: 30px; height: 30px; margin-left: -6px; padding: 5px; border: 0; border-radius: 8px; background: none; color: var(--accent); cursor: pointer; }
.doc-btn:hover { background: var(--accent-soft); }
.doc-btn:disabled { color: var(--muted); opacity: .45; background: none; cursor: default; }
.doc-btn svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.doc-icon > button:hover .mi-icon, .doc-icon > button[aria-expanded="true"] .mi-icon { box-shadow: inset 0 0 0 1.5px var(--accent); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.more-wrap { display: none; }
#moreMenu { min-width: 0; width: max-content; }
#examplesMenu .doc-title { display: block; width: 100%; max-width: none; border-color: var(--border); color: var(--text); }   /* on a phone */
.menu-doc { display: flex; align-items: center; gap: 2px; }
.menu-doc .menu-item { flex: 1; min-width: 0; }

/* ---------- dialogs ---------- */
.dlg {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px;
  background: var(--panel); color: var(--text); box-shadow: var(--shadow-pop);
  width: min(460px, calc(100vw - 32px));
}
.dlg.wide { width: min(720px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(15, 20, 30, .35); }
.dlg h2 { margin: 0 0 14px; font-size: 18px; }
.dlg-del { position: absolute; top: 16px; right: 16px; }   /* the corner of the dialog */
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 550; }
.dlg input:not([type=radio]) {
  border: 1px solid var(--border-strong); background: var(--panel); border-radius: 7px;
  padding: 7px 9px; font-size: 15px; color: var(--text);
}
.dlg input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; gap: 2px; }
.seg label { flex-direction: row; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { padding: 5px 14px; border-radius: 6px; color: var(--muted); font-size: 14px; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg.locked { border-color: transparent; padding: 0; }
.seg.locked label { cursor: default; }
.expr-field { margin-top: 14px; display: none; }
.expr-field > label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); font-weight: 550; }
form.is-calc .expr-field { display: block; }
.expr-line { display: flex; align-items: center; gap: 8px; }
.expr-line span { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.expr-line input { flex: 1; min-width: 0; font-family: var(--mono); }
.expr-field .hint { margin: 6px 0 0; line-height: 1.5; }
.dlg-error { color: var(--danger); min-height: 1.4em; margin: 10px 0 0; font-size: 13px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
#helpTabs { flex-wrap: wrap; }
/* the sections share one cell, so the box keeps the height of the longest */
.help { --help-max: 65vh; display: grid; margin-top: 12px; max-height: var(--help-max); overflow: auto; }
.help > section { grid-area: 1 / 1; }
/* hidden, they still set the height, but never more than the box: a short section has nothing to scroll */
.help > section:not(.shown) { visibility: hidden; max-height: var(--help-max); overflow: hidden; }
.help ul { margin: 0; padding-left: 18px; }
.help li { margin: 4px 0; line-height: 1.5; }

/* ---------- misc ---------- */
footer { flex: none; padding: 8px 16px; border-top: 1px solid var(--border); color: var(--muted); text-align: center; }
footer a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
footer img { height: 2.5em; vertical-align: middle; margin-right: 0.6em; }
/* lighting up on hover belongs to the dark theme; in the light theme the links simply show */
.dark-theme footer a { transition: color 0.2s; }
.dark-theme footer a:hover { color: var(--text); }
.dark-theme footer a img { opacity: 0.5; transition: opacity 0.2s; }
.dark-theme footer a:hover img { opacity: 1; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--panel); border-radius: 9px; padding: 9px 16px;
  box-shadow: var(--shadow-pop); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }
.pause-view {
  position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px); padding: 16px;
}
.pause-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop);
  padding: 22px 24px; max-width: 440px; text-align: center;
}
.pause-box h2 { margin: 0 0 8px; font-size: 18px; }
.pause-box p { margin: 0 0 16px; color: var(--muted); }
.toast-action {
  margin-left: 14px; border: 0; background: transparent; color: inherit; cursor: pointer;
  font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 0;
}
.drop-hint {
  position: fixed; inset: 12px; z-index: 60; border: 3px dashed var(--accent); border-radius: 16px;
  background: color-mix(in srgb, var(--accent-soft) 85%, transparent);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 650; color: var(--accent); pointer-events: none;
}

/* ---------- video tracking: in the place of the graph and the models ---------- */
.right.video-on > :not(.video-view) { display: none; }
.video-view { flex: 1 1 auto; }
.vv-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); padding: 12px; }
/* each tool of the bar with its settings, always shown: the bar does not move from one tool to another */
.vv-head { gap: 6px 18px; }
.vv-tool { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.vv-tool input, .vv-tool select { border: 1px solid var(--border-strong); background: var(--panel); border-radius: 7px; padding: 3px 6px; color: var(--text); }
.vv-tool :is(input, select):focus { outline: none; border-color: var(--accent); }
#vvLen { width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.vv-count { color: var(--text); font-weight: 600; margin-left: 6px; font-variant-numeric: tabular-nums; }
.vv-stage {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: #0b0d12; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
}
.vv-canvas-wrap { position: relative; flex: 1; min-height: 0; }
.vv-canvas-wrap canvas { position: absolute; inset: 0; display: block; cursor: crosshair; touch-action: none; }
.vv-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px);
  background: rgba(15, 20, 30, .82); color: #fff; border-radius: 8px; padding: 7px 14px;
  font-size: 13.5px; pointer-events: none; text-align: center;
}
.vv-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #c3cad6; padding: 32px; text-align: center; line-height: 1.6; max-width: 640px; margin: auto;
}
.vv-transport {
  flex: none; display: flex; align-items: center; gap: 4px; padding: 6px 10px;
  background: var(--panel); border-top: 1px solid var(--border);
}
.vv-transport input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); }
#vvSpeed { border: 1px solid var(--border-strong); background: var(--panel); border-radius: 7px; padding: 3px 4px; font-size: 13px; }
.vv-pos { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 190px; text-align: right; }
.btn:disabled, .icon-btn:disabled { opacity: .45; cursor: default; }

/* ---------- acquisition: in the place of the modelling, in one row ---------- */
:is(#btnAcq, #btnVideo)[aria-pressed="true"] { background: var(--panel-2); color: var(--accent); }
:is(#btnAcq, #btnVideo)[aria-pressed="true"] svg { color: var(--accent); }
#btnAcq.connected svg { color: var(--accent); }   /* an Arduino stays connected while the tab lives */
.acq-view { display: flex; flex-direction: column; min-height: 0; }
.acq-body { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 20px; padding: 10px 12px; overflow: auto; }
.acq-live { display: flex; flex-wrap: wrap; gap: 10px; min-width: 0; }
.acq-live .hint { margin: 0; }
/* the bar: the modes on the left, the readings in its middle, the board's settings on the right */
.acq-side { flex: 1 1 0; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.acq-side.end { justify-content: flex-end; }@media (min-width: 861px) { .acq-side { min-width: max-content; } }   /* never folded: the readings go down first */
/* a reading's height, the bar's tallest, which it keeps while only a text or a button shows */
.acq-center { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; min-height: var(--bar); }
/* a reading on one line, the name before the value, to keep the bar's height */
.acq-card { display: flex; align-items: baseline; gap: 6px; padding: 1px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.acq-card .k { font-size: 12px; color: var(--muted); }
/* a reading, ticked to be measured (no tick in Python) */
label.k { display: inline-flex; align-items: center; gap: 4px; align-self: center; cursor: pointer; }
label.k input { accent-color: var(--accent); margin: 0; }
label.k:has(input[hidden]) { cursor: default; }
/* the range of a console sensor, small enough for the card to keep its height */
.acq-card select { align-self: center; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--panel); padding: 1px 4px; font-size: 12px; }
.acq-card .v { font-size: 20px; line-height: 26px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
/* a recognized board, as tall as the voltage tabs it replaces */
.acq-board { border: 1px solid var(--border-strong); border-radius: 8px; padding: 5px 10px; font-size: 12.5px; font-weight: 550; color: var(--muted); white-space: nowrap; }
.acq-board b { color: var(--text); font-weight: 600; }
/* the settings, ending with the action; a field's height, kept when Python shows its sentence instead */
.acq-mode { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; min-height: var(--row); }
.acq-fields { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.acq-fields label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.acq-fields input { width: 64px; padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--panel); color: var(--text); }
.acq-fields input:focus { outline: none; border-color: var(--accent); }
:is(.acq-fields, .vv-tool) input.bad { border-color: var(--danger); color: var(--danger); }
#acqDuration, #acqInterval, #acqValue { text-align: right; font-variant-numeric: tabular-nums; }
/* Python: the program and what it prints, side by side, in the rest of the panel (its splitter sizes them) */
.acq-view { flex: 1 1 auto; overflow: auto; }
.acq-view > .acq-body { flex: none; }
.acq-python { flex: 1 1 220px; min-height: 120px; display: flex; padding: 12px; }   /* one line: the panel's height rules, not the program's */
.acq-python > .splitter { width: var(--split); }
@media (min-width: 861px) {
  .acq-python.split :is(textarea, .CodeMirror) { flex: none; width: calc((100% - var(--split)) * var(--code-share)); }
}
@media (max-width: 700px) { .acq-python { flex-direction: column; flex-basis: 360px; } }
.acq-python textarea, .acq-python pre { flex: 3 1 320px; box-sizing: border-box; min-width: 0; min-height: 0; margin: 0; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--panel); color: var(--text); font: 13px/1.5 var(--mono); overflow: auto; }
.acq-python textarea { resize: none; tab-size: 4; }
.acq-python textarea:focus { outline: none; border-color: var(--accent); }
/* CodeMirror (js/codemirror, loaded with the Python mode) takes the textarea's place and size; the sober palette
   of Brygame Studio: only keywords, strings, numbers and comments are coloured */
.acq-python .CodeMirror { flex: 3 1 320px; min-width: 0; min-height: 0; height: auto; border: 1px solid var(--border-strong); border-radius: var(--radius); font: 13px/1.5 var(--mono); }
.acq-python .CodeMirror-focused { border-color: var(--accent); }
/* :is() outweighs the theme sheets, loaded after this one */
.acq-python :is(.cm-s-default, .cm-s-material-darker).CodeMirror, .acq-python :is(.cm-s-default, .cm-s-material-darker) .CodeMirror-gutters { background: var(--panel); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) .CodeMirror-gutters { border-right: 1px solid var(--border); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) .CodeMirror-linenumber { color: var(--muted); }
.acq-python .cm-s-default .CodeMirror-cursor { border-left-color: var(--text); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) { color: var(--text); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) :is(span.cm-variable, span.cm-variable-2, span.cm-variable-3,
  span.cm-property, span.cm-operator, span.cm-punctuation, span.cm-bracket, span.cm-meta, span.cm-def, span.cm-builtin) { color: var(--text); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) span.cm-keyword { color: var(--cm-keyword); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) :is(span.cm-atom, span.cm-number) { color: var(--cm-number); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) :is(span.cm-string, span.cm-string-2) { color: var(--cm-string); }
.acq-python :is(.cm-s-default, .cm-s-material-darker) span.cm-comment { color: var(--cm-comment); font-style: italic; }
.acq-out { flex: 2 1 320px; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
.acq-out > .btn { align-self: flex-start; }
.acq-python pre { flex: 1 1 0; white-space: pre-wrap; }
.acq-python pre .error { color: var(--danger); }
.acq-python pre .note { color: var(--muted); }
/* the start of a run: a line between it and the one before */
.acq-python pre .run { display: block; }
.acq-python pre .run:not(:first-child) { border-top: 1px dashed var(--border-strong); margin-top: 6px; padding-top: 6px; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .tb span { display: none; }
  #downloadMenu { left: auto; right: 0; }
}
@media (max-width: 860px) {
  .video-view { flex: none; }
  .vv-body { grid-template-rows: 62vh; }   /* the graph's height */
  .vv-pos { min-width: 0; }
  body { height: auto; }
  .layout, .right { gap: 12px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .splitter { display: none; }
  .acq-python { gap: 10px; }  .table-panel { max-height: 60vh; }
  .graph-panel { height: 62vh; flex: none; }
  .model-panel { max-height: none; container: model / inline-size; }
  .brand span { display: none; }
  #examplesMenu { position: fixed; top: 57px; left: 8px; right: 8px; min-width: 0; }
  .topbar { gap: 8px; padding: 0 8px; }
}
@media (max-width: 600px) {
  #downloadMenu { position: fixed; top: 57px; left: 8px; right: 8px; min-width: 0; }
  /* the bar: the title goes into the document menu (app.js), video, acquisition, help and theme into the ⋮ menu */
  #btnVideo, #btnAcq, #btnHelp, #btnTheme, .actions > .tb-sep { display: none; }
  .more-wrap { display: block; }
}
