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

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: Georgia, 'Times New Roman', serif;
  background: #e8e8e8;
  color: #1a1a1a;
}

/* ── Canvas area ─────────────────────────────────────────────────────────── */
#canvas-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 22px;
  min-width: 0;
  background: #e8e8e8;
  padding: 12px 18px;
}

canvas {
  display: block;
  background: #fff;
  box-shadow: 0 3px 16px rgba(0,0,0,0.18);
  cursor: crosshair;
  /* width/height set by JS */
}
canvas.dragging { cursor: grabbing !important; }

#graph-canvas {
  width: 360px;
  min-width: 300px;
  max-width: 420px;
  height: auto;
  align-self: stretch;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  flex: 0 0 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 14px 12px;
  background: #fafafa;
  border-left: 1px solid #d0d0d0;
}

h1 {
  font-size: 14.5px;
  font-weight: normal;
  letter-spacing: 0.02em;
  border-bottom: 1px solid #ddd;
  padding-bottom: 8px;
}

body[data-reward-mode="binary"] #sidebar {
  background: linear-gradient(180deg, #f6fbf8 0%, #fafafa 38%);
}

body[data-reward-mode="arbitrary"] #sidebar {
  background: linear-gradient(180deg, #fbf8f4 0%, #fafafa 38%);
}

.panel {
  border: 1px solid #e4e4e4;
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
}

.mode-panel {
  border-width: 1.5px;
  padding: 12px;
}

body[data-reward-mode="binary"] .mode-panel {
  border-color: #b9dec6;
  background: linear-gradient(180deg, #f5fbf6 0%, #ffffff 100%);
  box-shadow: 0 4px 14px rgba(56, 123, 74, 0.08);
}

body[data-reward-mode="arbitrary"] .mode-panel {
  border-color: #e6cfb3;
  background: linear-gradient(180deg, #fdf8f1 0%, #ffffff 100%);
  box-shadow: 0 4px 14px rgba(142, 101, 47, 0.08);
}

.panel h2 {
  font-size: 11.5px;
  font-weight: normal;
  font-style: italic;
  color: #666;
  margin-bottom: 9px;
  letter-spacing: 0.04em;
}
.panel h2 .sub { font-size: 10px; color: #aaa; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.mode-option {
  padding: 10px 8px;
  border-radius: 8px;
  font-size: 12px;
  border-width: 1.5px;
  background: #f4f4f4;
}

.mode-option.active {
  color: #fff;
}

body[data-reward-mode="binary"] .mode-option.active {
  background: #2f7d4a;
  border-color: #2f7d4a;
}

body[data-reward-mode="arbitrary"] .mode-option.active {
  background: #a56a2a;
  border-color: #a56a2a;
}

.mode-copy {
  font-size: 11px;
  line-height: 1.45;
  color: #586069;
}

/* ── Toggle switches ─────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  font-size: 12.5px;
  cursor: pointer;
  gap: 6px;
}
.toggle-row span:first-child { flex: 1; }
.toggle-row strong {
  display: block;
  font-weight: 600;
  color: #2a2a2a;
}

.toggle-copy {
  display: none;
}

.display-group + .display-group {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eceff3;
}

.group-title {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a8f98;
  margin-bottom: 9px;
  font-style: normal;
}

.sub-toggle-block {
  margin: 2px 0 10px 14px;
  padding-left: 10px;
  border-left: 2px solid #e3e7ec;
}

.sub-toggle-row {
  font-size: 11.5px;
  margin-bottom: 5px;
}

.sub-toggle-block.is-disabled {
  opacity: 0.45;
}

.binary-only-group {
  margin: 10px 0 4px 0;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #e0e5ea;
  background: #f8faf9;
  transition: opacity 0.2s, background 0.2s;
}

.binary-only-group.is-disabled {
  opacity: 0.45;
  background: #f5f5f5;
  pointer-events: none;
}

body[data-reward-mode="binary"] .binary-only-group {
  border-color: #c8ddd0;
  background: #f5fbf7;
}

body[data-reward-mode="arbitrary"] .binary-only-group {
  border-color: #e5dcd0;
  background: #faf8f5;
}

.switch { position: relative; display: inline-block; width: 36px; height: 19px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.knob {
  position: absolute; inset: 0;
  background: #ccc; border-radius: 19px; transition: background 0.2s;
}
.knob::before {
  content: ''; position: absolute;
  width: 13px; height: 13px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
input:checked + .knob { background: #4a7fcb; }
input:checked + .knob::before { transform: translateX(17px); }

/* ── Sliders ─────────────────────────────────────────────────────────────── */
.slider-row {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 8px; font-size: 12.5px;
}

.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  font-size: 12.5px;
}

.select-row label {
  flex: 0 0 82px;
  color: #555;
}

.select-row select {
  flex: 1;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  background: #fbfbfb;
  color: #333;
  font-family: Georgia, serif;
}

select:disabled,
input:disabled + .knob {
  opacity: 0.45;
  cursor: not-allowed;
}
.slider-row label { flex: 0 0 22px; }
.slider-row input[type=range] {
  flex: 1; accent-color: #4a7fcb; height: 4px;
}
.slider-row output {
  flex: 0 0 44px; text-align: right;
  font-size: 11px; font-family: monospace; color: #555;
}

/* ── Action list ─────────────────────────────────────────────────────────── */
.action-row {
  display: flex; align-items: center; gap: 5px;
  margin-bottom: 5px; font-size: 12px;
}
.action-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0,0,0,0.2); }
.action-label { flex: 0 0 22px; font-style: italic; font-size: 11.5px; }
.action-coord { flex: 1; display: flex; gap: 3px; }
.coord-input {
  width: 52px; font-size: 10px; padding: 1px 3px;
  border: 1px solid #ccc; border-radius: 3px;
  font-family: monospace; text-align: right; color: #555;
  background: #fafafa;
}
.coord-input:focus { outline: none; border-color: #4a7fcb; background: #fff; }
.action-r-wrap { display: flex; align-items: center; gap: 3px; font-size: 11px; color: #555; }
.action-binary-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #555;
}
.action-binary-wrap input { accent-color: #4a7fcb; }
.action-r-input {
  width: 48px; font-size: 11px; padding: 2px 4px;
  border: 1px solid #ccc; border-radius: 3px;
  font-family: monospace; text-align: right;
  background: #fafafa;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
button {
  padding: 4px 10px; font-size: 11.5px;
  border: 1px solid #c8c8c8; border-radius: 4px;
  cursor: pointer; background: #f5f5f5;
  font-family: Georgia, serif; color: #333;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #eaeff8; border-color: #9ab; }
button:active { background: #dae4f4; }

/* ── Info box ────────────────────────────────────────────────────────────── */
#info-box {
  font-size: 10.5px; font-family: monospace;
  line-height: 1.75; color: #333; white-space: pre;
  background: #f4f6fa; border-radius: 4px;
  padding: 7px 9px;
}

.hint {
  font-size: 10px; color: #aaa; margin-top: 4px; font-style: italic;
}

body[data-reward-mode="arbitrary"] #binary-tools-note {
  color: #a56a2a;
}

body[data-reward-mode="binary"] #binary-tools-note {
  color: #6b7f72;
}

/* ── Info icon + popup ───────────────────────────────────────────────────── */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 1px solid #aaa;
  color: #888;
  font-size: 9px;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
  font-style: normal;
  line-height: 1;
}
.info-popup {
  display: none;
  position: absolute;
  left: 18px; top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 5px 9px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.13);
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
}
.info-icon:hover .info-popup { display: block; }

/* ── KaTeX inline tweaks ──────────────────────────────────────────────────── */
.katex { font-size: 1em; }
