:root {
  --bg: #0a0a0a;
  --panel: #111;
  --border: #333;
  --text: #e8e8e8;
  --muted: #888;
  --accent: #fff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.operator-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  flex-wrap: wrap;
}

.op-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  margin-right: -1px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}

.op-btn:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.op-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  z-index: 1;
}

.main-row {
  display: flex;
  flex: 1;
  min-height: 0;
}

.canvas-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 8px;
}

.canvas-row {
  flex: 1;
  display: flex;
  min-height: 0;
  gap: 8px;
  max-height: calc(100vh - 120px);
}

.field-canvas-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  min-height: 0;
}

#field-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #000;
  border: 1px solid var(--border);
  cursor: crosshair;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.profile-panel {
  width: min(420px, 32vw);
  min-width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  padding: 8px 6px;
  background: #050505;
  min-height: 0;
  align-self: stretch;
}

.profile-panel .panel-title {
  margin-bottom: 2px;
}

.profile-hint {
  margin: 0 0 6px;
}

.profile-operator-banner {
  margin: 0 0 6px;
  padding: 6px 8px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--text);
  border: 1px solid var(--border);
  background: #0d0d0d;
}

.profile-chart-wrap {
  flex: 1;
  min-height: 280px;
  border: 1px solid var(--border);
  background: #000;
}

.canvas-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.right-panel {
  width: 380px;
  min-width: 320px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-block {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.param-row {
  margin-bottom: 10px;
}

.param-row--pair {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.param-cell {
  flex: 1;
  min-width: 0;
  position: relative;
}

.param-label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.param-row label,
.param-label-row label {
  display: block;
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

.param-row input[type="number"],
.param-cell input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  background: #000;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 6px;
}

.param-info-btn {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  padding: 0;
  font-size: 9px;
  font-weight: 600;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: #0a0a0a;
  color: var(--muted);
  cursor: pointer;
}

.param-info-btn:hover,
.param-info-btn[aria-expanded="true"] {
  color: var(--text);
  border-color: var(--text);
}

.param-info-popup {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% - 2px);
  padding: 8px;
  background: #111;
  border: 1px solid var(--border);
  font-size: 10px;
  line-height: 1.4;
  color: #ccc;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
}

.param-info-popup p {
  margin: 0 0 6px;
}

.param-info-popup p:last-child {
  margin-bottom: 0;
}

.param-info-units {
  color: var(--text);
  font-weight: 600;
}

.param-hint {
  margin: 4px 0 0;
  font-size: 10px;
  line-height: 1.35;
  color: var(--muted);
}

.param-coords-banner {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text);
}

.field-row, .check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}

.field-row select, .field-row input[type="number"] {
  flex: 1;
  max-width: 200px;
  background: #000;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 2px 4px;
}

.check-row input {
  margin-right: 6px;
}

.primary-btn {
  width: 100%;
  margin-top: 8px;
  background: var(--text);
  color: #000;
  border: none;
  padding: 6px;
  cursor: pointer;
  font-weight: 600;
}

.primary-btn:hover {
  background: #ccc;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  margin: 0;
}

.inspect-line {
  margin: 4px 0;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  word-break: break-word;
}

.operator-io-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25em 0.45em;
  align-items: baseline;
}

.operator-io-sep {
  color: var(--muted);
}

.operator-formula {
  margin: 6px 0 0;
  padding: 8px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  font-family: ui-monospace, "Cambria Math", serif;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e0e0e0;
}

.inspect-pending {
  color: var(--muted);
  font-style: italic;
}

.inspect-trace-detail {
  margin: 8px 0 0;
  padding: 8px;
  border: 1px solid var(--border);
  background: #0a0a0a;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ccc;
  max-height: 320px;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

.sim-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}

.sim-bar button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 3px 8px;
  cursor: not-allowed;
}

.sim-note {
  color: var(--muted);
  margin-left: 8px;
  font-size: 11px;
}

#preset-params .param-row {
  margin-bottom: 8px;
}

#preset-params .param-row--pair {
  margin-bottom: 10px;
}