*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
}

:root {
  --bg: #f3f4f6;
  --panel: #fff;
  --border: #d4d8df;
  --text: #171a1f;
  --muted: #687281;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, .14);
  --mark: #b42318;
  --radius: 8px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

body.runtime-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

body.runtime-page .topbar {
  position: static;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  padding: 6px 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

body.runtime-page .topbar h1 {
  font-size: 14px;
  white-space: nowrap;
}

.topbar-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

body.runtime-page .topbar-fields {
  min-width: 0;
  flex-wrap: nowrap;
  gap: 5px;
}

.is-hidden {
  display: none !important;
}

label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

select,
input[type="range"] {
  accent-color: var(--accent);
}

input[type="range"] {
  width: 100%;
}

select {
  min-width: 230px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.radio-group {
  display: grid;
  gap: 4px;
  align-items: start;
  margin: 0;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.radio-group legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.radio-group label {
  display: inline-flex;
  grid-template-columns: none;
  gap: 5px;
  align-items: center;
  color: var(--text);
  white-space: nowrap;
}

body.runtime-page .radio-group {
  gap: 2px;
  padding: 3px 5px;
}

body.runtime-page #flapGroup {
  min-height: 48px;
}

body.runtime-page .radio-group legend {
  font-size: 10px;
}

body.runtime-page .radio-group label,
body.runtime-page .check-field {
  gap: 3px;
  font-size: 11px;
  white-space: nowrap;
}

body.runtime-page .radio-group input,
body.runtime-page .check-field input {
  margin: 0;
}

.check-field {
  display: inline-flex;
  grid-template-columns: none;
  gap: 6px;
  align-items: center;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  padding: 14px;
}

.runtime-page .runtime-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.chart-shell {
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.chart-stage {
  position: relative;
  width: min(100%, 1160px);
  min-width: 760px;
  margin: 0 auto;
}

.runtime-shell .chart-shell {
  display: flex;
  min-height: 0;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}

.runtime-shell .chart-stage {
  min-width: 0;
}

.runtime-shell .chart-stage img,
.runtime-shell .chart-stage canvas {
  height: 100%;
}

.runtime-shell .controls {
  min-height: 0;
}

.runtime-shell .control-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 12px;
  padding: 10px;
}

.chart-stage img,
.chart-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}

.chart-stage canvas {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}

.controls {
  display: grid;
  align-content: start;
  gap: 12px;
}

.control-grid,
.readout {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.control-grid {
  display: grid;
  gap: 14px;
}

.control-grid label {
  color: var(--text);
}

.control-grid label span {
  color: var(--muted);
}

.control-grid output {
  justify-self: end;
  font-variant-numeric: tabular-nums;
}

.range-with-marker {
  position: relative;
  display: block;
}

.zero-marker {
  position: absolute;
  left: 25%;
  top: 50%;
  width: 4px;
  height: 24px;
  border: 1px solid #fff;
  border-radius: 2px;
  background: var(--mark);
  box-shadow: 0 0 0 1px var(--mark);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.readout {
  display: grid;
  gap: 10px;
}

.readout div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
}

.readout dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.readout dd {
  margin: 0;
  min-width: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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