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

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #1b1b1b;
  background: #f4f4f1;
}

body {
  display: flex;
  flex-direction: column;
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #2c2c2c;
  color: #fff;
  flex-shrink: 0;
  user-select: none;
}

.toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: #555;
  margin: 2px 6px;
}

#module-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#toolbar button {
  appearance: none;
  border: 1px solid #555;
  background: #3a3a3a;
  color: #fff;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
}

#toolbar button:hover {
  background: #4a4a4a;
}

#toolbar .mode-btn.active,
#toolbar .module-btn.active {
  background: #1a73e8;
  border-color: #1a73e8;
}

#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: row;
}

#settings-panel {
  position: relative;
  width: 280px;
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #ccc;
  z-index: 5;
}

#settings-panel .panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 12px 12px;
}

#settings-panel h2 {
  margin: 14px 0 8px;
  font-size: 13px;
  font-weight: 700;
}

#settings-panel h2:first-child {
  margin-top: 0;
}

#optimizer-type,
#loss-type,
#dataset-type,
#dataset-chart-pair,
#test-chart-pair {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  margin-bottom: 6px;
}

#dataset-chart-wrap,
#test-plot-wrap {
  flex: 0 0 180px;
  height: 180px;
  margin: 8px 0;
}

#dataset-chart-wrap[hidden],
#test-plot-wrap[hidden],
#dataset-chart-pair[hidden],
#test-chart-pair[hidden] {
  display: none;
}

#dataset-sample {
  margin-top: 12px;
}

#dataset-media img,
#fail-media img {
  display: block;
  width: 100%;
  max-width: 220px;
  background: #111;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#dataset-media audio,
#fail-media audio {
  display: block;
  width: 100%;
}

#dataset-media .dataset-text,
#fail-media .dataset-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

#dataset-nav,
#fail-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

#dataset-index,
#fail-index {
  width: 6ch;
  flex: none;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 2px 4px;
  text-align: center;
}

#dataset-nav button,
#fail-nav button {
  appearance: none;
  border: 1px solid #555;
  background: #3a3a3a;
  color: #fff;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}

#dataset-nav button:hover:not(:disabled),
#fail-nav button:hover:not(:disabled) {
  background: #4a4a4a;
}

#dataset-nav button:disabled,
#fail-nav button:disabled {
  opacity: 0.45;
  cursor: default;
}

#dataset-label,
#dataset-size,
#dataset-input-shape,
#dataset-label-shape,
#dataset-num-labels,
#test-loss,
#test-accuracy,
#test-failures,
#fail-label,
#fail-pred,
#fail-test-index,
#fail-size {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  margin-top: 8px;
  white-space: pre-wrap;
}

.setting-arg {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 3px 0;
  flex-wrap: wrap;
}

.setting-arg input,
.setting-arg select {
  flex: 1;
  min-width: 72px;
  font: inherit;
  padding: 2px 4px;
}

.resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}

.resize-handle-right {
  right: 0;
}

.resize-handle-left {
  left: 0;
}

#canvas {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: auto;
  position: relative;
  background-color: #f4f4f1;
  background-image: radial-gradient(#d4d4ce 1px, transparent 1px);
  background-size: 20px 20px;
  cursor: default;
}

body[data-mode="connect"] #canvas {
  cursor: crosshair;
}

body[data-placing="true"] #canvas {
  cursor: copy;
}

#workspace {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

#edges,
#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

#nodes {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.node {
  position: absolute;
  width: 220px;
  background: #fff;
  border: 1.5px solid #222;
  border-radius: 4px;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.08);
  user-select: none;
  pointer-events: auto;
  cursor: grab;
}

body[data-mode="connect"] .node {
  cursor: crosshair;
}

.node.dragging {
  cursor: grabbing;
  z-index: 5;
}

.node.selected,
#ghost.selected {
  outline: 2px dashed #1a73e8;
  outline-offset: 4px;
}

.node-title {
  font-weight: 700;
  font-size: 13px;
  padding: 8px 10px 6px;
  border-bottom: 1px solid #ddd;
}

.node-args {
  padding: 6px 10px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.arg {
  padding: 2px 0;
  white-space: nowrap;
}

.arg-value {
  color: #0b57d0;
  cursor: text;
}

.arg-value input,
.arg-value select {
  font: inherit;
  color: inherit;
  max-width: 96px;
  padding: 0 2px;
  margin: 0;
  border: 1px solid #1a73e8;
  border-radius: 2px;
  background: #fff;
}

#ghost {
  position: absolute;
  width: 220px;
  background: #fff;
  border: 1.5px dashed #222;
  border-radius: 4px;
  opacity: 0.55;
  pointer-events: none;
  z-index: 4;
}

#ghost .node-title {
  font-weight: 700;
  font-size: 13px;
  padding: 8px 10px 6px;
  border-bottom: 1px solid #ddd;
}

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
}

.edge-line {
  fill: none;
  stroke: #222;
  stroke-width: 2;
  pointer-events: none;
}

.edge.selected .edge-line {
  stroke: #1a73e8;
}

.edge-marquee {
  display: none;
  fill: none;
  stroke: #1a73e8;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.edge.selected .edge-marquee {
  display: inline;
}

#arrow path {
  fill: #222;
}

#arrow-selected path {
  fill: #1a73e8;
}

#preview-line {
  fill: none;
  stroke: #1a73e8;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

#generate-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-left: 1px solid #ccc;
  box-shadow: -4px 0 12px rgba(0, 0, 0, 0.12);
}

#generate-panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
}

.panel-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid #ccc;
}

#settings-panel > .panel-tabs {
  padding: 0 8px;
}

#generate-panel .panel-tabs {
  border-bottom: none;
}

.tab-btn {
  appearance: none;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #333;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn.active {
  border-bottom-color: #1a73e8;
  font-weight: 700;
}

.tab-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.tab-page[hidden] {
  display: none;
}

#train-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#generate-panel #panel-close,
#generate-panel #btn-copy,
#generate-panel #btn-train,
#generate-panel #btn-stop,
#generate-panel #btn-test {
  appearance: none;
  border: 1px solid #555;
  background: #3a3a3a;
  color: #fff;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
}

#generate-panel #panel-close:hover,
#generate-panel #btn-copy:hover,
#generate-panel #btn-train:hover:not(:disabled),
#generate-panel #btn-stop:hover:not(:disabled),
#generate-panel #btn-test:hover:not(:disabled) {
  background: #4a4a4a;
}

#generate-panel #btn-train:disabled,
#generate-panel #btn-stop:disabled,
#generate-panel #btn-test:disabled {
  opacity: 0.45;
  cursor: default;
}

#loss-chart-wrap {
  flex: 0 0 180px;
  height: 180px;
}

#loss-chart-wrap[hidden] {
  display: none;
}

#generated-code {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f7f7f4;
}

#generated-code code {
  font-family: inherit;
  font-size: inherit;
}

#traceback {
  flex: 0 0 140px;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 8px;
  border: 1px solid #c44;
  border-radius: 4px;
  background: #fff6f6;
  color: #1b1b1b;
}

#traceback[hidden] {
  display: none;
}

#test-error {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #a11;
  white-space: pre-wrap;
}

#test-error[hidden],
#test-stats[hidden],
#fail-sample[hidden] {
  display: none;
}
