:root {
  --bg: #f5f6f9;
  --panel: #ffffff;
  --border: #e2e5ec;
  --text: #1d2130;
  --muted: #8a90a0;
  --primary: #3b6ef5;
  --accent: #12a37a;
  --danger: #d8453c;
}

* { box-sizing: border-box; }

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

header { max-width: 1180px; margin: 0 auto 20px; }
h1 { margin: 0 0 6px; font-size: 26px; }
h2 { margin: 0 0 14px; font-size: 17px; }
h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.subtitle { margin: 0; color: var(--muted); }
code { background: #eceef4; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

main {
  max-width: 1320px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 540px 1fr;
  gap: 20px;
  align-items: start;
}

.right-column { display: flex; flex-direction: column; gap: 20px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

#board {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}

.hint { color: var(--muted); font-size: 12px; margin: 8px 0 14px; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

button {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #f0f2f7; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
button.accent:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: #f0c4c1; }

select, input[type="number"] {
  font: inherit;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* --- кнопки-цифры для добавления в набор --- */
.add-row { gap: 12px; }
.add-label { font-size: 13px; color: var(--muted); }
.digit-buttons { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.digit-buttons button {
  width: 38px;
  padding: 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  border-color: #c9d7fb;
}
.digit-buttons button:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* --- предсказание --- */
.prediction { font-size: 15px; display: flex; align-items: center; gap: 12px; min-height: 46px; }
.prediction .big { font-size: 42px; font-weight: 700; line-height: 1; }
.muted { color: var(--muted); font-size: 13px; }

.bars { display: flex; flex-direction: column; gap: 3px; margin-top: 10px; }
.bar-row { display: grid; grid-template-columns: 16px 1fr 52px; align-items: center; gap: 8px; font-size: 12px; }
.bar-label { color: var(--muted); text-align: center; }
.bar-track { height: 10px; background: #eef0f5; border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: #c3cddf; transition: width .12s; }
.bar-row.best .bar-fill { background: var(--accent); }
.bar-row.best .bar-label, .bar-row.best .bar-value { color: var(--text); font-weight: 600; }
.bar-value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- параметры обучения --- */
.params {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.params label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.params small { color: var(--muted); font-size: 11px; }
.params input[type="text"] { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.arch-field { grid-column: span 2; }

.stats { display: flex; gap: 24px; margin: 14px 0; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }

#chart { width: 100%; height: 160px; background: #fbfcfe; border-radius: 8px; }

/* --- датасет --- */
.counts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.count {
  min-width: 42px; padding: 6px 4px; text-align: center;
  border: 1px solid var(--border); border-radius: 8px; background: #fbfcfe;
}
.count b { display: block; font-size: 14px; }
.count span { font-size: 12px; color: var(--muted); }
.count.empty { border-color: #f0c4c1; }
.count.total { background: #eef2fd; border-color: #c9d7fb; }

.samples { display: flex; flex-wrap: wrap; gap: 6px; max-height: 260px; overflow-y: auto; }
.sample { position: relative; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 2px; }
.sample canvas { display: block; cursor: pointer; image-rendering: pixelated; }
.sample-label {
  position: absolute; left: 2px; bottom: 2px; font-size: 10px;
  background: rgba(255,255,255,.85); padding: 0 3px; border-radius: 3px;
}
.sample-del {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px;
  padding: 0; line-height: 1; border-radius: 50%; font-size: 13px; color: var(--danger);
}

/* --- визуализация сети --- */
.panel.wide { grid-column: 1 / -1; }

.viz-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  font-size: 12px; color: var(--muted); margin-bottom: 12px;
}
.viz-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.dark { background: #2a2f3d; }
.dot.pos { background: #dc4a4a; }
.dot.neg { background: #4a5ee6; }

#graph {
  width: 100%;
  height: auto;
  aspect-ratio: 1200 / 470;
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.viz-columns {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 24px;
  margin-top: 8px;
}
.viz-block h3 { margin-top: 0; }
.viz-block h4 { margin: 14px 0 8px; font-size: 13px; }

.neuron-head { display: flex; gap: 16px; align-items: flex-start; }
.neuron-map { border: 1px solid var(--border); border-radius: 6px; image-rendering: pixelated; }
.neuron-details dl { margin: 0; display: grid; grid-template-columns: auto auto; gap: 3px 12px; font-size: 13px; }
.neuron-details dt { color: var(--muted); }
.neuron-details dd { margin: 0; font-variant-numeric: tabular-nums; }

.votes { display: flex; flex-direction: column; gap: 3px; }
.vote { display: grid; grid-template-columns: 14px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; }
.vote span { color: var(--muted); text-align: center; }
.vote b { text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
.vote-track { height: 9px; background: #eef0f5; border-radius: 5px; overflow: hidden; }
.vote-fill { height: 100%; border-radius: 5px; }
.vote-fill.pos { background: #dc4a4a; }
.vote-fill.neg { background: #4a5ee6; }

.template-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.template { position: relative; }
.template canvas {
  display: block; width: 64px; height: 64px;
  border: 1px solid var(--border); border-radius: 6px; image-rendering: pixelated;
}
.template span {
  position: absolute; left: 3px; bottom: 3px; font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.85); padding: 0 4px; border-radius: 3px;
}

.weight-maps {
  max-height: 380px; overflow-y: auto; padding: 2px;
}
.wm-layer + .wm-layer { margin-top: 14px; }
.wm-layer h4 { margin: 0 0 8px; font-size: 13px; }
.weight-maps-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.weight-map { position: relative; cursor: pointer; }
.weight-map canvas {
  display: block; width: 52px; height: 52px;
  border: 1px solid var(--border); border-radius: 5px; image-rendering: pixelated;
}
.weight-map:hover canvas { border-color: #9fb2e8; }
.weight-map.selected canvas { border: 2px solid var(--primary); }
.weight-map span {
  position: absolute; left: 2px; bottom: 2px; font-size: 9px; color: var(--muted);
  background: rgba(255,255,255,.8); padding: 0 3px; border-radius: 3px;
}

footer { max-width: 1180px; margin: 24px auto 0; color: var(--muted); font-size: 13px; }

@media (max-width: 1080px) {
  main { grid-template-columns: 1fr; }
  .viz-columns { grid-template-columns: 1fr; }
}
