:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-subtle: #f0f1ee;
  --border: #d5d8d3;
  --border-strong: #aeb4ad;
  --text: #171917;
  --muted: #565d57;
  --faint: #626963;
  --input: #ffffff;
  --accent: #1d211e;
  --focus: #1769aa;
  --izh: #2259a8;
  --hh: #a64b20;
  --current: #6440a0;
  --recorded: #167054;
  --threshold: #176c9c;
  --peak: #28753b;
  --ahp: #9a6119;
  --warning: #8b5316;
  --success: #1f6a36;
  --header-height: 72px;
  color-scheme: light;
}

body[data-theme="dark"] {
  --bg: #111411;
  --surface: #181c19;
  --surface-subtle: #202521;
  --border: #394039;
  --border-strong: #687169;
  --text: #edf0ed;
  --muted: #b7bdb8;
  --faint: #98a09a;
  --input: #202521;
  --accent: #edf0ed;
  --focus: #72b7ef;
  --izh: #79aaf0;
  --hh: #e89a71;
  --current: #b7a0ea;
  --recorded: #62c69f;
  --threshold: #67b8e2;
  --peak: #77cb87;
  --ahp: #e1b666;
  --warning: #e0ae67;
  --success: #75c98a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="number"],
input[type="text"],
input[type="file"] {
  min-height: 38px;
}

button {
  color: inherit;
}

.disclosure-heading {
  margin: 0;
  font: inherit;
}

.disclosure-heading .sec-lbl {
  width: 100%;
}

b,
strong {
  font-weight: 600;
}

:focus-visible {
  outline: 3px solid var(--focus) !important;
  outline-offset: 2px;
}

input[aria-invalid="true"] {
  border-color: var(--hh) !important;
  outline: 2px solid color-mix(in srgb, var(--hh) 35%, transparent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  color: var(--surface);
  background: var(--text);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* Header ----------------------------------------------------------------- */
.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.hdr-brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.hdr-title {
  font-family: "Newsreader", Georgia, serif;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0;
}

.hdr-tag {
  color: var(--muted);
  font-size: 13px;
}

.hdr-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-btn,
.utility-btn {
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.theme-btn:hover,
.utility-btn:hover {
  background: var(--surface-subtle);
}

/* Page structure --------------------------------------------------------- */
.app {
  width: 100%;
  max-width: none;
  margin: 0;
  background: var(--surface);
  border-inline: 0;
}

.research-workbench,
.control-rail,
.results-section {
  min-width: 0;
}

.results-section {
  position: relative;
}

.control-rail {
  overflow-x: hidden;
}

.sec,
.ws {
  padding: 26px 28px;
  border-bottom: 1px solid var(--border);
}

.section-heading,
.results-heading {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin-bottom: 22px;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.section-index {
  padding-top: 4px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.section-heading h1,
.section-heading h2,
.results-heading h2 {
  font-family: "Newsreader", Georgia, serif;
  font-size: 24px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.section-heading p {
  max-width: 760px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.sec-lbl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.sec-lbl.toggler {
  cursor: pointer;
}

.toggler-title {
  font-family: "Newsreader", Georgia, serif;
  font-size: 21px;
  font-weight: 500;
}

.toggler-detail {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.sec-chev {
  color: var(--muted);
  font-size: 13px;
  transition: transform 150ms ease;
}

.sec.collapsed .sec-chev {
  transform: rotate(-90deg);
}

.sec.collapsed .sec-body {
  display: none;
}

.sec-lbl + .sec-body,
.disclosure-heading + .sec-body {
  margin-top: 20px;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.table-scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Context help ----------------------------------------------------------- */
[data-help] {
  position: relative;
}

[data-help]::after {
  position: absolute;
  z-index: 120;
  top: calc(100% + 7px);
  left: 0;
  width: max-content;
  max-width: min(280px, 80vw);
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  background: var(--text);
  color: var(--surface);
  content: attr(data-help);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 100ms ease 180ms, transform 100ms ease 180ms, visibility 0s linear 280ms;
}

[data-help]:hover::after,
[data-help]:focus-visible::after,
[data-help]:focus-within::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 180ms;
}

.hdr-actions [data-help]::after,
.panel-actions [data-help]::after,
.result-controls [data-help]::after,
.model-toolbar [data-help]::after {
  right: 0;
  left: auto;
}

body[data-theme="dark"] [data-help]::after {
  background: var(--text);
  color: var(--bg);
}

/* Shared form controls --------------------------------------------------- */
.field,
.model-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label,
.model-field {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.field-note {
  color: var(--faint);
  font-size: 12px;
  line-height: 1.4;
}

.inline-math,
.math-label {
  font-family: Georgia, "Times New Roman", serif;
}

.inline-math i {
  font-style: italic;
}

.inline-math sub,
.inline-math sup {
  font-size: 0.72em;
  line-height: 0;
}

.field input:not([type="range"]),
.wide-sel,
.hdr-sel,
.method-opts input,
.pfrow input[type="number"],
.chan-io input[type="number"],
.select-control select,
.gate-label,
.gate input[type="number"],
.gate select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--input);
  color: var(--text);
}

.field input:not([type="range"]):hover,
.wide-sel:hover,
.hdr-sel:hover,
.method-opts input:hover,
.pfrow input[type="number"]:hover,
.select-control select:hover,
.gate-label:hover {
  border-color: var(--text);
}

.prng {
  width: 100%;
  min-height: 24px;
  accent-color: var(--accent);
  cursor: pointer;
}

.chk,
.radio,
.vpill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.chk input,
.radio input,
.vpill input {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.standalone-check {
  margin-top: 14px;
}

.btn,
.mini-btn,
.disclosure {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn:hover,
.mini-btn:hover,
.disclosure:hover {
  border-color: var(--text);
  background: var(--surface-subtle);
}

.btn:disabled,
.mini-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.pri {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.btn.pri:hover {
  opacity: 0.88;
}

body[data-theme="dark"] .btn.pri {
  color: var(--bg);
}

/* Data ------------------------------------------------------------------- */
.trace-input,
#vexpCard {
  display: none;
}

.seg-plain {
  display: inline-flex;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-strong);
}

.seg-plain button {
  min-height: 42px;
  padding: 8px 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.seg-plain button.active {
  border-bottom-color: var(--text);
  color: var(--text);
  font-weight: 600;
}

.trace-mode-picker {
  margin-bottom: 18px;
}

.trace-mode-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trace-mode-seg {
  margin: 4px 0 0;
}

.ic-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 16px;
  align-items: end;
}

.field.amp {
  grid-column: span 2;
}

.file-label {
  display: flex;
  grid-column: span 2;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.file-label input[type="file"] {
  width: 100%;
  padding: 5px;
  border: 1px solid var(--border-strong);
  background: var(--input);
  color: var(--text);
}

#fileName:empty,
#vfileName:empty {
  display: none;
}

#fileName,
#vfileName {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.hint {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.file-summary {
  margin-top: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.file-summary:empty {
  display: none;
}

/* Model ------------------------------------------------------------------ */
.model-toolbar {
  display: flex;
  align-items: end;
  gap: 22px;
  margin-bottom: 22px;
  padding: 14px 16px;
  border-block: 1px solid var(--border);
  background: var(--surface-subtle);
}

.model-reset {
  margin-left: auto;
}

.model-field {
  width: min(100%, 300px);
}

.model-context {
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.model-context strong {
  color: var(--text);
}

.core-view-switch {
  display: inline-flex;
  align-self: flex-start;
  align-items: stretch;
  min-height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  overflow: hidden;
  background: var(--surface);
}

.core-view-label {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.core-view-switch button {
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.core-view-switch button.active {
  background: var(--text);
  color: var(--surface);
}

.params-wrap {
  display: grid;
  grid-template-columns: 1fr;
}

body.model-compare .params-wrap {
  grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr);
  gap: 22px;
}

.params-divider {
  background: var(--border);
}

body:not(.model-compare) .params-divider {
  display: none;
}

.param-col {
  min-width: 0;
}

.param-col-hdr {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.dot-izh {
  background: var(--izh);
}

.dot-hh {
  background: var(--hh);
}

.pgrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 18px;
}

.pgrid.parameter-strip {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(188px, 220px);
  gap: 14px;
  width: 100%;
  padding: 2px 2px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scroll-snap-type: inline proximity;
  scrollbar-width: thin;
}

.parameter-strip .pcell {
  scroll-snap-align: start;
}

body.model-compare .pgrid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pcell {
  min-width: 0;
}

.prow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.plbl {
  min-width: 0;
  flex: 1;
  color: var(--muted);
  font-size: 13px;
}

.pnum {
  width: 82px;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--input);
  color: var(--text);
  text-align: right;
}

.disclosure {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  color: var(--muted);
}

.disclosure .chev {
  transition: transform 150ms ease;
}

.disclosure.open .chev {
  transform: rotate(180deg);
}

.disclosure-body {
  display: none;
  margin-top: 12px;
  padding: 14px 16px;
  border-left: 3px solid var(--border-strong);
  background: var(--surface-subtle);
}

.disclosure-body.open {
  display: block;
}

.equation-parameters {
  margin: 10px 0 4px;
}

.manual-gates {
  margin-top: 14px;
  padding-top: 14px !important;
  border-top: 1px solid var(--border);
}

.pgrid.parameter-strip.manual-gates {
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  grid-auto-flow: row;
  grid-auto-columns: auto;
  overflow: visible;
  padding-inline: 0;
}

.manual-gate-control {
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
}

.manual-gate-control .prow {
  align-items: flex-start;
  margin-bottom: 6px;
}

.manual-gate-name {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.manual-gate-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 4px;
}

.manual-gate-unit {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.live-math {
  margin: 0 0 12px;
  padding: 8px 10px;
  overflow-x: auto;
  border-left: 3px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 14px;
  line-height: 1.55;
}

.live-math .eq {
  margin: 0;
  padding: 2px 0;
  white-space: nowrap;
}

.live-math .katex-display {
  margin: 0.2em 0;
  text-align: left;
}

#izhLiveMath {
  border-left-color: var(--izh);
  --equation-accent: var(--izh);
}

#hhLiveMath {
  border-left-color: var(--hh);
  --equation-accent: var(--hh);
}

.eq-c {
  width: 68px;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--input);
  color: var(--text);
  text-align: center;
}

/* Editable model equations ---------------------------------------------- */
.equation-editor {
  min-width: 0;
}

.equation-editor-surface {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 10px 12px 6px;
  overflow: visible;
}

.live-math .equation-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  min-height: 48px;
  padding: 27px 0 10px;
  overflow: visible;
  border-bottom: 1px solid var(--border);
  white-space: normal;
}

.equation-row.has-equation-values {
  padding-bottom: 12px;
}

.equation-row[data-equation-label]::before {
  position: absolute;
  top: 7px;
  left: 0;
  content: attr(data-equation-label);
  color: var(--faint);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.live-math .equation-row:last-child {
  border-bottom: 0;
}

.equation-fragment {
  flex: 0 0 auto;
  font-size: 16px;
}

.equation-term {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: baseline;
  gap: 3px;
  white-space: nowrap;
}

.equation-operator {
  padding-inline: 1px;
}

.equation-token {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  width: auto;
  min-width: 0;
  padding: 0;
  font-family: "Inter", system-ui, sans-serif;
  vertical-align: middle;
}

.equation-token-label {
  min-width: 0;
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
}

.equation-token .eq-c,
.equation-token .pnum {
  width: 58px;
  min-height: 30px;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--equation-accent, var(--focus)) 7%, var(--surface));
  font-family: "Inter", system-ui, sans-serif;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.equation-token .eq-c:hover,
.equation-token .eq-c:focus,
.equation-token .pnum:hover,
.equation-token .pnum:focus {
  border-color: var(--equation-accent, var(--focus));
  outline: none;
}

.equation-value {
  position: relative;
  border-radius: 3px;
}

.equation-value.is-linked {
  outline: 2px solid color-mix(in srgb, var(--equation-accent, var(--focus)) 48%, transparent);
  outline-offset: 3px;
}

.equation-pair {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 27px 0 12px;
  border-bottom: 1px solid var(--border);
}

.equation-pair[data-equation-label]::before {
  position: absolute;
  top: 7px;
  left: 0;
  content: attr(data-equation-label);
  color: var(--faint);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.live-math .equation-pair > .equation-row,
.chan-card .equation-pair > .equation-row {
  min-height: 0;
  padding: 0;
  border-bottom: 0;
}

.equation-reference-row {
  color: var(--text);
}

.equation-edit-row {
  padding-top: 8px !important;
  border-top: 1px dashed var(--border) !important;
}

.equation-edit-row .equation-value {
  display: inline-flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 84px;
  min-width: 84px;
  max-width: 84px;
  padding: 4px 5px 3px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: color-mix(in srgb, var(--equation-accent, var(--focus)) 6%, var(--surface));
  font-family: "Inter", system-ui, sans-serif;
  vertical-align: middle;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.equation-edit-row .equation-value.is-linked,
.equation-edit-row .equation-value:focus-within {
  border-color: var(--equation-accent, var(--focus));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--equation-accent, var(--focus)) 14%, transparent);
  outline: none;
}

.equation-edit-row .equation-token-label,
.equation-edit-row .equation-parameter-label {
  display: none;
}

.equation-edit-row .scrub-control {
  display: inline-flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 84px;
  min-width: 84px;
  max-width: 84px;
}

.equation-edit-row .equation-exact {
  display: flex;
  width: 100%;
}

.equation-edit-row .equation-value input[type="number"] {
  width: 100% !important;
  min-width: 0;
  min-height: 30px;
  padding: 3px 5px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.equation-edit-row .equation-value input[type="number"]:focus {
  outline: none;
}

.equation-edit-row .equation-range {
  position: static;
  display: block;
  width: 100% !important;
  min-height: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--equation-accent, var(--focus));
  cursor: pointer;
}

.equation-reference-row .equation-value {
  cursor: pointer;
}

.equation-reference-row .scrub-control {
  display: inline-flex;
  flex: 0 0 auto;
  min-width: 0;
}

.equation-reference-row .equation-power .equation-parameter-label {
  display: inline-flex;
}

.equation-pair:last-child {
  border-bottom: 0;
}

.equation-unit {
  color: var(--faint);
  font-size: 10px;
  line-height: 1.2;
  text-align: right;
  white-space: nowrap;
}

.equation-value > .equation-unit,
.equation-value .equation-exact > .equation-unit {
  display: none;
}

.equation-note {
  color: var(--faint);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
}

.equation-value.is-inactive {
  opacity: 0.52;
}

.equation-control-name,
.equation-control-unit {
  display: none;
}

.equation-initial-condition {
  color: var(--muted);
}

.equation-gate-initialization {
  flex: 0 0 100%;
  margin: 4px 0 0;
  font-family: Georgia, serif;
}

.equation-computed-note {
  color: var(--faint);
  white-space: nowrap;
}

.compatibility-mirrors[hidden] {
  display: none !important;
}

.equation-parameters .eq-c {
  width: 76px;
  font-family: "Inter", system-ui, sans-serif;
}

#modelSec.core-controls-only .equation-reference-row,
#modelSec.core-controls-only .equation-edit-row .equation-fragment,
#modelSec.core-controls-only .equation-edit-row .equation-note,
#modelSec.core-controls-only .equation-edit-row .equation-parameter-mirror,
#modelSec.core-controls-only .equation-edit-row .equation-computed-note,
#modelSec.core-controls-only #izhLiveMath > .equation-initial-condition {
  display: none;
}

#modelSec.core-controls-only .equation-editor-surface {
  gap: 12px;
  padding-block: 6px 10px;
  border-left: 0;
  background: transparent;
}

#modelSec.core-controls-only .equation-pair {
  gap: 0;
  padding: 0;
  border-bottom: 0;
}

#modelSec.core-controls-only .equation-pair::before {
  display: none;
}

#modelSec.core-controls-only .equation-edit-row {
  align-items: stretch;
  flex-direction: column;
  gap: 0;
  width: 100%;
  min-height: 0;
  padding: 0 !important;
  border-top: 0 !important;
}

#modelSec.core-controls-only .equation-edit-row .equation-term {
  display: contents;
}

#modelSec.core-controls-only .equation-edit-row .equation-value {
  display: grid;
  grid-template-columns: minmax(130px, 1.4fr) 56px 78px minmax(100px, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 9px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#modelSec.core-controls-only .equation-edit-row .equation-token-label,
#modelSec.core-controls-only .equation-edit-row .equation-parameter-label {
  display: block;
  width: auto;
  min-height: 0;
  text-align: left;
}

#modelSec.core-controls-only .equation-edit-row .equation-control-name,
#modelSec.core-controls-only .equation-edit-row .equation-control-unit {
  display: block;
}

#modelSec.core-controls-only .equation-edit-row .equation-control-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

#modelSec.core-controls-only .equation-edit-row .equation-control-unit {
  color: var(--faint);
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
}

#modelSec.core-controls-only .equation-edit-row .equation-value input[type="number"] {
  width: 78px !important;
  min-height: 34px;
  padding: 5px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--input);
  text-align: right;
}

#modelSec.core-controls-only .equation-edit-row .equation-range {
  width: 100% !important;
  min-height: 20px;
  height: 20px;
  accent-color: var(--text);
}

#modelSec.core-controls-only .equation-edit-row .equation-value.is-linked,
#modelSec.core-controls-only .equation-edit-row .equation-value:focus-within {
  border-color: var(--border);
  box-shadow: none;
}

#mathSec.collapsed {
  padding-bottom: 0;
}

@media (max-width: 520px) {
  #modelSec.core-controls-only .equation-edit-row .equation-value {
    grid-template-columns: minmax(0, 1fr) 52px 78px;
  }

  #modelSec.core-controls-only .equation-edit-row .equation-control-name {
    grid-column: 1;
    grid-row: 1;
  }

  #modelSec.core-controls-only .equation-edit-row .equation-token-label,
  #modelSec.core-controls-only .equation-edit-row .equation-parameter-label {
    grid-column: 2;
    grid-row: 1;
  }

  #modelSec.core-controls-only .equation-edit-row .equation-value input[type="number"] {
    grid-column: 3;
    grid-row: 1;
  }

  #modelSec.core-controls-only .equation-edit-row .equation-range {
    grid-column: 1 / 3;
    grid-row: 2;
  }

  #modelSec.core-controls-only .equation-edit-row .equation-control-unit {
    grid-column: 3;
    grid-row: 2;
    text-align: right;
  }
}

.scientific-note {
  max-width: 760px;
  margin-top: 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--hh);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 14px;
}

.scientific-note strong {
  color: var(--text);
}

/* Ionic-current editor --------------------------------------------------- */
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.pal-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: grab;
  user-select: none;
}

.pal-chip:hover {
  border-color: var(--text);
  background: var(--surface-subtle);
}

.pal-chip.dragging {
  opacity: 0.45;
}

.pal-swatch {
  width: 10px;
  height: 10px;
}

.pal-add {
  color: var(--muted);
  font-weight: 600;
}

.dropzone {
  min-height: 72px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
}

.dropzone.drag-over {
  border-style: solid;
  border-color: var(--focus);
  background: var(--surface-subtle);
}

.dz-hint {
  padding: 18px 0;
  color: var(--faint);
  text-align: center;
}

.dropzone.has-channels .dz-hint {
  display: none;
}

.chan-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.chan-card {
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
}

.chan-card:last-child {
  border-bottom: 1px solid var(--border);
}

.chan-card.disabled {
  border-left-color: var(--muted);
  background: color-mix(in srgb, var(--surface) 92%, var(--muted));
}

.chan-card-hdr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 7px 4px;
  cursor: default;
}

.chan-card-hdr .grip {
  color: var(--faint);
  cursor: grab;
}

.chan-name {
  min-width: 40px;
  flex: 1 1 90px;
  padding: 5px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.chan-en {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.chan-del,
.gate-del,
.chan-move,
.chan-chev {
  min-width: 36px;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.chan-del:hover,
.gate-del:hover {
  color: var(--hh);
}

.chan-move {
  min-width: 28px;
  padding: 0;
}

.chan-move:disabled {
  opacity: 0.3;
  cursor: default;
}

.chan-chev {
  padding: 0;
  color: var(--muted);
  transition: transform 150ms ease;
}

.chan-card.collapsed .chan-chev {
  transform: rotate(-90deg);
}

.chan-card.collapsed .chan-body {
  display: none;
}

.chan-body {
  padding: 4px 4px 16px;
}

.channel-equation,
.gate-equation,
.chan-current-equation,
.gate-equations {
  margin: 0 0 10px;
  padding: 7px 9px;
  overflow-x: auto;
  border-left: 2px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: Georgia, serif;
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
}

.gate-equation,
.gate-equations {
  color: var(--muted);
}

.chan-formula {
  order: 2;
  min-width: 0;
  flex: 1 0 100%;
  padding: 1px 0 3px 29px;
  overflow: hidden;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chan-formula .katex {
  font-size: 1em;
}

.chan-current-equation .katex,
.gate-equations .katex {
  font-size: 1em;
}

.equation-fallback {
  white-space: pre-wrap;
}

.scrub-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(56px, 72px);
  gap: 4px 7px;
  align-items: center;
  min-width: 110px;
  flex: 1 1 120px;
}

.scrub-control > .scrub-label {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

.scrub-unit {
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
}

.scrub-control input[type="number"] {
  width: 100%;
  min-width: 0;
}

.scrub-range {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 24px;
  accent-color: var(--accent);
  cursor: pointer;
}

.channel-reset,
.chan-reset {
  margin-left: auto;
}

.chan-io {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}

.chan-io label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

/* Equation-native channel controls ------------------------------------- */
.channel-equation-guide {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.chan-card .equation-editor {
  min-width: 0;
}

.current-equation-editor {
  margin: 0 4px 10px;
  padding: 8px 12px;
  max-width: 100%;
  overflow-x: auto;
  border-left-color: var(--ch-accent, var(--border-strong));
  white-space: normal;
  --equation-accent: var(--ch-accent, var(--focus));
}

.chan-card .equation-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  min-height: 48px;
  padding: 27px 0 10px;
  overflow: visible;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.45;
  white-space: normal;
  --equation-accent: var(--ch-accent, var(--focus));
}

.chan-card .equation-row.has-equation-values {
  padding-bottom: 12px;
}

.chan-card .current-equation-row {
  min-height: 0;
}

.equation-math {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
}

.equation-math .katex {
  font-size: 1em;
}

.chan-card .equation-parameter {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  max-width: none;
  flex: 0 0 auto;
  padding: 0;
  vertical-align: middle;
}

.chan-card .equation-parameter-label {
  min-width: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12px;
  line-height: 1.1;
  white-space: nowrap;
}

.chan-card .equation-range {
  accent-color: var(--equation-accent, var(--focus));
}

.equation-exact {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-family: "Inter", system-ui, sans-serif;
}

.chan-card .equation-exact input[type="number"] {
  width: 58px !important;
  min-height: 30px;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: color-mix(in srgb, var(--equation-accent, var(--focus)) 7%, var(--surface));
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.chan-card .equation-exact input[type="number"]:hover,
.chan-card .equation-exact input[type="number"]:focus {
  border-color: var(--equation-accent, var(--focus));
  outline: none;
}

.chan-card .equation-unit {
  color: var(--faint);
  font-size: 9px;
  line-height: 1;
  text-align: left;
}

.equation-power {
  display: inline-flex;
  align-self: flex-start;
  margin: -7px 0 0 -2px;
}

.equation-power .equation-parameter {
  gap: 2px;
}

.equation-power .equation-parameter-label {
  display: none;
}

.equation-power .equation-exact input[type="number"] {
  width: 44px !important;
  min-height: 30px;
  padding: 3px 4px;
}

.equation-inline-power {
  margin-top: -8px;
}

.equation-fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  vertical-align: middle;
}

.equation-numerator,
.equation-denominator {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 3px 5px;
}

.equation-numerator {
  border-bottom: 1px solid currentColor;
}

.rate-outer-fraction {
  flex: 0 1 auto;
}

.rate-inner-fraction,
.gate-fraction {
  flex: 0 1 auto;
}

.equation-parameter-mirror {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 4px;
  border-bottom: 1px dotted var(--border-strong);
  color: var(--muted);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 11px;
}

.equation-mirror-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.equation-reference-row .equation-parameter-mirror {
  padding: 0;
  border-bottom: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: inherit;
  cursor: pointer;
}

.equation-edit-row .equation-parameter-mirror {
  display: inline-flex;
  width: 84px;
  min-width: 84px;
  max-width: 84px;
  min-height: 59px;
  align-items: center;
  justify-content: center;
  padding: 4px 5px;
  border: 1px dashed var(--border-strong);
  border-radius: 3px;
  background: color-mix(in srgb, var(--equation-accent, var(--focus)) 3%, var(--surface));
  vertical-align: middle;
  cursor: pointer;
}

.equation-edit-row .equation-parameter-mirror .equation-mirror-symbol,
.equation-edit-row .equation-parameter-mirror .equation-unit {
  display: none;
}

.equation-edit-row .equation-parameter-mirror .equation-mirror-value {
  font-size: 13px;
  text-align: center;
}

.equation-reference-row .equation-parameter-mirror.is-linked,
.equation-edit-row .equation-parameter-mirror.is-linked,
.equation-edit-row .equation-parameter-mirror:focus {
  border-color: var(--equation-accent, var(--focus));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--equation-accent, var(--focus)) 14%, transparent);
  outline: none;
}

.equation-structure {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin: 4px 0 6px;
  font-family: "Inter", system-ui, sans-serif;
}

.channel-structure {
  margin-bottom: 10px;
}

.kinetics-editor + .kinetics-editor,
.kinetics-editor > .equation-row + .equation-row {
  margin-top: 7px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.kinetics-editor {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

.chan-name-math,
.pal-symbol,
.channel-symbol {
  font-family: Georgia, "Times New Roman", serif;
}

.gate {
  margin-top: 10px;
  padding: 10px 12px;
  border-left: 2px solid var(--border-strong);
  background: var(--surface-subtle);
}

.gate-hdr,
.kin {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.gate-hdr {
  margin-bottom: 8px;
}

.gate-title {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 600;
}

.gate-label {
  width: 48px;
  min-height: 34px;
  padding: 4px 6px;
  text-align: center;
}

.gate-title .gv {
  color: var(--text);
}

.gate-hdr label,
.kin .kf {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.gate-hdr input[type="number"] {
  width: 58px;
}

.gate-del {
  margin-left: auto;
}

.kin {
  margin-top: 6px;
  font-size: 13px;
}

.kin .kin-lbl {
  min-width: 18px;
  color: var(--text);
  font-weight: 600;
  font-style: italic;
}

.kin input[type="number"] {
  width: 68px;
}

.kin .kf {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.kin .kf span {
  color: var(--faint);
  font-size: 12px;
}

.select-control {
  display: inline-flex;
  min-width: 110px;
  flex: 1 1 132px;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.select-control select {
  min-width: 0;
}

.chan-io .scrub-control,
.gate-hdr .scrub-control,
.kin .scrub-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(56px, 72px);
  align-items: center;
}

.chan-io .select-control,
.gate-hdr .select-control,
.kin .select-control {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
}

.channel-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.channel-card-actions .gate-add {
  margin-top: 0;
}

.gate-add {
  margin-top: 10px;
}

.chan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* Run and results -------------------------------------------------------- */
.action-section {
  background: var(--surface-subtle);
}

.run-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding-left: 66px;
}

.stat {
  min-height: 22px;
  margin-left: auto;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.stat.err {
  color: #a23535;
}

body[data-theme="dark"] .stat.err {
  color: #ff8a8a;
}

.results-heading {
  grid-template-columns: minmax(180px, 0.4fr) minmax(0, 1fr);
  align-items: end;
}

.results-heading > div:first-child {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 14px;
  align-items: baseline;
}

.result-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

#layoutResetBtn {
  align-self: flex-end;
}

.vpills,
.marks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}

.vpill {
  padding: 0;
  border: 0;
  border-radius: 0;
}

.vpill.on {
  color: var(--text);
  font-weight: 500;
}

.vpill.is-disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.marks > span {
  color: var(--faint);
  font-size: 13px;
}

.results-stale-banner {
  position: absolute;
  z-index: 25;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  overflow: hidden;
  background: color-mix(in srgb, var(--warning) 22%, transparent);
  color: transparent;
  font-size: 0;
  pointer-events: none;
}

.results-stale-banner::after {
  position: absolute;
  inset-block: 0;
  width: 36%;
  background: var(--warning);
  content: "";
  animation: stale-results-sweep 900ms linear infinite;
}

@keyframes stale-results-sweep {
  from { transform: translateX(-110%); }
  to { transform: translateX(310%); }
}

.workspace-grid.results-stale {
  --card-border: color-mix(in srgb, var(--warning) 45%, var(--border));
}

.workspace-grid.results-stale .workspace-panel {
  border-color: var(--card-border);
}

.plot-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: row;
  gap: 14px;
  align-items: start;
}

.workspace-panel.panel-wide {
  grid-column: 1 / -1;
}

.plot-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

.workspace-panel {
  cursor: default;
}

.workspace-panel.dragging,
.workspace-panel.panel-dragging {
  opacity: 0.45;
}

.card-hdr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.panel-title {
  min-width: 0;
}

.trace-label,
.model-badge {
  margin-left: 0;
  padding-left: 10px;
  border-left: 2px solid var(--border-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.panel-grip,
.panel-move {
  min-height: 30px;
  padding: 4px 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.panel-grip {
  cursor: grab;
}

.panel-grip:active {
  cursor: grabbing;
}

.panel-grip:hover,
.panel-move:hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
}

.tag-exp {
  border-left-color: var(--recorded);
  color: var(--recorded);
}

.tag-hh,
.badge-hh {
  border-left-color: var(--hh);
  color: var(--hh);
}

.badge-izh {
  border-left-color: var(--izh);
  color: var(--izh);
}

.plot-area {
  height: 220px;
  padding: 4px;
}

.workspace-panel.panel-wide .plot-area {
  height: 290px;
}

#plotVexp,
#plotChan {
  height: 100%;
}

.plot-area > div {
  height: 100%;
}

/* Features --------------------------------------------------------------- */
.feat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  border-top: 1px solid var(--border);
}

.feat-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.fk {
  color: var(--muted);
  font-size: 13px;
}

.fv {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.feat-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.feat-tbl th,
.feat-tbl td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.feat-tbl th {
  color: var(--muted);
  font-weight: 600;
}

.feat-tbl td {
  font-variant-numeric: tabular-nums;
}

.feat-tbl td:first-child {
  color: var(--muted);
}

.feat-cmp th:not(:first-child),
.feat-cmp td:not(:first-child) {
  text-align: right;
}

.feat-cmp td.dcol {
  color: var(--warning);
  font-weight: 600;
}

/* Fitting --------------------------------------------------------------- */
.fit-status {
  margin-bottom: 20px;
  padding: 10px 12px;
  border-left: 3px solid var(--warning);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 14px;
}

.fit-status.ok {
  border-left-color: var(--success);
  color: var(--text);
}

.fit-start-assist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.fit-start-assist strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.fit-start-assist p {
  color: var(--muted);
  font-size: 13px;
}

.fit-start-assist .mini-btn {
  flex: 0 0 auto;
}

.fit-cols {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.25fr) minmax(240px, 0.8fr);
  gap: 28px;
}

.fit-block {
  min-width: 0;
}

.fit-block + .fit-block {
  padding-left: 24px;
  border-left: 1px solid var(--border);
}

.fit-block-hdr {
  display: block;
  margin-bottom: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.ef-eq {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 400;
}

.pfrow {
  display: grid;
  grid-template-columns: auto minmax(86px, 1fr) repeat(3, 66px);
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
  font-size: 13px;
}

.pfrow.head {
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}

.pfrow .pf-name {
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.pfrow.head span:nth-child(n + 3),
.pf-current {
  min-width: 0;
  text-align: right;
}

.pf-current {
  overflow: hidden;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}

.pfrow input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.pfrow.inactive-fit-param {
  color: var(--faint);
}

.pfrow.inactive-fit-param .pf-name,
.pfrow.inactive-fit-param .pf-current {
  color: var(--faint);
}

.pf-unavailable-reason {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
}

.radio-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.radio {
  align-items: flex-start;
  line-height: 1.45;
}

.radio input {
  margin-top: 2px;
}

.rec-tag {
  margin-left: 5px;
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.obj-builder {
  margin-top: 18px;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
}

.obj-builder.off {
  display: none;
}

.obj-builder-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.obj-sub {
  display: block;
  max-width: 420px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.obj-weights {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ow-row {
  display: grid;
  grid-template-columns: 130px minmax(100px, 1fr) 52px;
  gap: 12px;
  align-items: center;
}

.ow-name {
  min-width: 0;
  color: var(--text);
  font-size: 13px;
}

.ow-name .ow-unit {
  color: var(--faint);
  font-size: 12px;
}

.ow-slider {
  width: 100%;
  min-height: 28px;
  accent-color: var(--accent);
  cursor: pointer;
}

.ow-val {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.obj-breakdown {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  overflow-x: auto;
}

.obj-idle {
  color: var(--faint);
}

.obj-bd-tbl {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.obj-bd-tbl th,
.obj-bd-tbl td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.obj-bd-tbl th {
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}

.obj-bd-tbl th:first-child,
.obj-bd-tbl td:first-child {
  color: var(--text);
  text-align: left;
}

.obj-bd-tbl .bar-cell {
  width: 68px;
}

.obj-bd-bar {
  min-width: 1px;
  height: 6px;
  background: var(--accent);
}

.obj-bd-tbl tfoot td {
  border-top: 2px solid var(--border-strong);
  color: var(--text);
  font-weight: 600;
}

.obj-gate {
  display: block;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-left: 3px solid var(--border-strong);
  background: var(--surface-subtle);
  font-size: 13px;
}

.obj-gate.matched {
  border-left-color: var(--success);
  color: var(--success);
}

.obj-gate.mismatch {
  border-left-color: var(--warning);
  color: var(--warning);
}

.fit-sub,
.method-opts,
.fit-run {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.fit-sub {
  margin-top: 16px;
}

.fit-sub .field {
  flex: 1 1 170px;
}

.wide-sel {
  appearance: auto;
}

.method-opts {
  margin-top: 14px;
}

.fit-initial {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.method-opts label {
  display: flex;
  flex: 1 1 84px;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.fit-run {
  align-items: center;
  margin: 24px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.fit-progress {
  height: 7px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.fit-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 160ms linear;
}

.fit-readout {
  min-height: 24px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.fit-comparisons {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.fit-comparison-head,
.fit-comparison-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.fit-comparison-head {
  justify-content: space-between;
}

.fit-comparison-head h3 {
  margin: 0 0 3px;
  font-size: 14px;
}

.fit-comparison-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.fit-comparison-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.fit-comparison-row {
  display: grid;
  grid-template-columns: auto 10px minmax(150px, auto) minmax(210px, 1fr);
  align-items: center;
  gap: 9px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.fit-comparison-row strong {
  color: var(--text);
}

.fit-comparison-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.fit-result-map {
  margin-top: 12px;
  padding-top: 12px;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.fit-result-map h3 {
  margin-bottom: 3px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.fit-result-map > p {
  margin-bottom: 9px;
  color: var(--muted);
  line-height: 1.45;
}

.fit-result-map > .fit-result-summary {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.fit-result-map.is-applied {
  border-top-color: var(--success);
}

.fit-value-map {
  min-width: 650px;
  border-top: 1px solid var(--border);
}

.fit-value-row {
  display: grid;
  grid-template-columns: minmax(130px, 1.3fr) repeat(5, minmax(78px, 0.75fr));
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.fit-value-row span:not(:first-child) {
  text-align: right;
}

.fit-value-row.head {
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}

.fit-value-row:not(.head) span:first-child {
  color: var(--text);
}

.fit-applied {
  box-shadow: inset 0 0 0 2px var(--success);
}

.fit-curve-card {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.fit-curve-card h3 {
  font-size: 14px;
  font-weight: 600;
}

.fit-curve {
  height: 180px;
  margin-top: 8px;
}

.paper-figure-section {
  border-top: 1px solid var(--border-strong);
}

.paper-builder-controls,
.paper-figure-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.paper-builder-controls {
  margin: 18px 0 14px;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}

.paper-builder-controls > label:not(.chk) {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.paper-title-control {
  flex: 1 1 330px;
}

.paper-title-control input {
  width: 100%;
}

.paper-figure-plot {
  width: 100%;
  aspect-ratio: 1600 / 1100;
  min-height: 0;
  border: 1px solid var(--border);
  background: #fff;
}

.paper-figure-actions {
  justify-content: flex-end;
  padding-top: 14px;
}

.paper-figure-actions .stat {
  margin-right: auto;
  margin-left: 0;
}

/* Model visibility ------------------------------------------------------- */
body:not(.model-hh):not(.model-compare) #channelSec,
body:not(.model-hh):not(.model-compare) #hhParamsCol,
body.model-izh #hhParamsCol,
body.model-hh #izhParamsCol,
body.model-izh .hh-current-field,
body.model-hh .izh-current-field,
body:not(.model-hh):not(.model-compare) .plot-card-hh,
body:not(.model-hh):not(.model-compare) .vpill-hh {
  display: none;
}

/* Mathematical reference ------------------------------------------------ */
.math-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 28px;
}

.math-card {
  min-width: 0;
  padding: 18px 0 20px;
  border-top: 1px solid var(--border);
}

.math-card h3 {
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 600;
}

.math-card p,
.math-list li {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.math-card p {
  margin: 8px 0;
}

.math-card b {
  color: var(--text);
}

.math-card .math-note {
  margin-top: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--faint);
  font-size: 13px;
}

.math-card-accent {
  border-top-color: var(--text);
}

.eq:not(.equation-row) {
  max-width: 100%;
  margin: 8px 0;
  padding: 4px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex {
  font-size: 1.03em;
}

.katex-display {
  margin: 0.45em 0;
}

.math-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
  padding-left: 20px;
}

/* Responsive layout ------------------------------------------------------ */
@media (min-width: 1180px) {
  .research-workbench {
    display: grid;
    grid-template-columns: clamp(480px, 36vw, 720px) minmax(620px, 1fr);
    align-items: start;
    height: calc(100dvh - var(--header-height));
  }

  .control-rail {
    height: 100%;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    scrollbar-gutter: stable;
  }

  .control-rail .sec {
    padding: 22px 20px;
  }

  .control-rail .section-heading {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 9px;
    margin-bottom: 17px;
  }

  .control-rail .section-heading h1,
  .control-rail .section-heading h2,
  .results-heading h2 {
    font-size: 22px;
  }

  .control-rail .model-toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .control-rail .model-context {
    order: 3;
    width: 100%;
    padding-bottom: 0;
  }

  .control-rail .params-wrap,
  body.model-compare .control-rail .params-wrap {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  body.model-compare .control-rail .params-divider {
    width: 100%;
    height: 1px;
  }

  .control-rail .ic-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-rail .field.amp,
  .control-rail .file-label {
    grid-column: 1 / -1;
  }

  .control-rail .run-bar {
    padding-left: 0;
  }

  .control-rail .fit-cols {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .control-rail .fit-block + .fit-block,
  .control-rail .fit-block:last-child {
    grid-column: auto;
    padding-top: 20px;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .results-section {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100%;
    max-height: calc(100dvh - var(--header-height));
    overflow: auto;
    scrollbar-gutter: stable;
  }

  .results-heading {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 16px;
  }

  .result-controls {
    align-items: flex-start;
  }

  #layoutResetBtn {
    align-self: flex-start;
  }
}

@media (max-width: 1100px) {
  .fit-cols {
    grid-template-columns: 1fr 1fr;
  }

  .fit-block:last-child {
    grid-column: 1 / -1;
    padding-top: 20px;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

}

@media (max-width: 900px) {
  .app {
    border-inline: 0;
  }

  body.model-compare .params-wrap {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  body.model-compare .params-divider {
    width: 100%;
    height: 1px;
  }

  body.model-compare .pgrid:not(.parameter-strip) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .results-heading {
    grid-template-columns: 1fr;
  }

  .result-controls {
    align-items: flex-start;
  }

  .fit-cols {
    grid-template-columns: 1fr;
  }

  .fit-block + .fit-block,
  .fit-block:last-child {
    grid-column: auto;
    padding-top: 20px;
    padding-left: 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 700px) {
  body {
    font-size: 14px;
  }

  button,
  select,
  input[type="number"],
  input[type="text"],
  input[type="file"] {
    min-height: 44px;
  }

  .hdr {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 14px 16px;
  }

  .hdr-brand {
    min-width: 180px;
    flex: 1 1 210px;
    flex-direction: column;
    gap: 1px;
  }

  .hdr-actions {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .hdr-title {
    font-size: 24px;
  }

  .hdr-tag {
    max-width: 220px;
    font-size: 12px;
  }

  .theme-btn {
    min-height: 44px;
  }

  .utility-btn {
    min-height: 44px;
  }

  .sec,
  .ws {
    padding: 22px 16px;
  }

  .section-heading,
  .results-heading > div:first-child {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 8px;
  }

  .section-heading h1,
  .section-heading h2,
  .results-heading h2 {
    font-size: 22px;
  }

  .sec-lbl {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 10px;
  }

  .toggler-title {
    font-size: 19px;
  }

  .toggler-detail {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .sec-chev {
    grid-column: 2;
    grid-row: 1;
  }

  .ic-row {
    grid-template-columns: 1fr;
  }

  .field.amp,
  .file-label {
    grid-column: auto;
  }

  .model-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
  }

  .model-field {
    width: 100%;
  }

  .model-context {
    padding-bottom: 0;
  }

  .pgrid:not(.parameter-strip),
  body.model-compare .pgrid:not(.parameter-strip) {
    grid-template-columns: 1fr;
  }

  .live-math {
    font-size: 14px;
  }

  .pgrid.parameter-strip.manual-gates,
  body.model-compare .pgrid.parameter-strip.manual-gates {
    grid-template-columns: 1fr;
    grid-auto-columns: auto;
  }

  .equation-token .eq-c,
  .equation-token .pnum,
  .chan-card .equation-exact input[type="number"],
  .equation-edit-row .equation-value input[type="number"] {
    min-height: 44px;
  }

  .equation-edit-row .equation-range {
    min-height: 44px;
    height: 44px;
  }

  .run-bar {
    align-items: stretch;
    padding-left: 0;
  }

  .run-bar .btn {
    flex: 1 1 140px;
  }

  .run-bar .chk {
    flex-basis: 100%;
  }

  .stat {
    flex-basis: 100%;
    margin-left: 0;
  }

  .vpills,
  .marks {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .plot-area {
    height: 260px;
  }

  .workspace-panel.panel-wide .plot-area {
    height: 260px;
  }

  #plotVexp,
  #plotChan {
    height: 220px;
  }

  .pfrow {
    grid-template-columns: auto minmax(76px, 1fr) repeat(3, 56px);
    gap: 5px;
    font-size: 12px;
  }

  .pfrow input[type="number"] {
    padding-inline: 5px;
  }

  .obj-builder-hdr {
    flex-direction: column;
  }

  .ow-row {
    grid-template-columns: minmax(0, 1fr) 52px;
  }

  .ow-name {
    grid-column: 1 / -1;
  }

  .math-grid {
    grid-template-columns: 1fr;
  }

  .math-card {
    min-width: 0;
  }

  .chan-io {
    flex-direction: column;
  }

  .pgrid.parameter-strip,
  body.model-compare .pgrid.parameter-strip {
    grid-template-columns: none;
    grid-auto-columns: minmax(220px, 84vw);
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .workspace-panel.panel-wide {
    grid-column: auto;
  }

  .fit-start-assist {
    align-items: stretch;
    flex-direction: column;
  }

  .fit-start-assist .mini-btn {
    align-self: flex-start;
  }

  .fit-comparison-row {
    grid-template-columns: auto 10px 1fr;
  }

  .fit-comparison-row > span:last-child {
    grid-column: 3;
  }

  .paper-builder-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .paper-figure-plot {
    min-height: 430px;
  }

  .panel-actions {
    width: 100%;
    flex: 1 0 100%;
    margin-left: 0;
  }

  .panel-grip,
  .panel-move {
    flex: 1 1 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .results-stale-banner::after {
    width: 100%;
    animation: none !important;
  }
}
