:root {
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #7a7974;
  --line: #dddcd7;
  --grid: #ebeae6;
  --pos: #2a78d6;
  --neg: #e34948;
  --zero: #d6d5d0;
  --node-zero: #f0efec;
  --accent: #2a78d6;
  --hi: #eda100;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #8f8e86;
    --line: #34332f;
    --grid: #2a2a27;
    --pos: #3987e5;
    --neg: #e66767;
    --zero: #45443f;
    --node-zero: #383835;
    --accent: #3987e5;
    --hi: #c98500;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #8f8e86;
  --line: #34332f;
  --grid: #2a2a27;
  --pos: #3987e5;
  --neg: #e66767;
  --zero: #45443f;
  --node-zero: #383835;
  --accent: #3987e5;
  --hi: #c98500;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 13px; margin: 14px 0 4px; }
.muted { color: var(--ink-3); }
.hint { color: var(--ink-2); font-size: 12.5px; margin: 4px 0 8px; }
.num {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: var(--surface); font-size: 12px;
}

.top { padding: 20px 16px 8px; max-width: 1500px; margin: 0 auto; }
.lead { color: var(--ink-2); margin: 0; }
main { max-width: 1500px; margin: 0 auto; padding: 8px 16px 32px; display: grid; gap: 16px; }
.row { display: grid; gap: 16px; }
.row1 { grid-template-columns: 250px minmax(0, 1fr) 250px; }
.row2 { grid-template-columns: minmax(0, 1fr) 440px; }
@media (max-width: 1150px) {
  .row1 { grid-template-columns: 250px minmax(0, 1fr); }
  #out-card { grid-column: 1 / -1; }
  .row2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .row1 { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

button, select, input {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--ink-3); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
button.danger { color: var(--neg); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: var(--surface); }

/* --- шаблон --- */
#template { width: 100%; max-width: 190px; display: block; margin: 0 auto; }
#template .seg-line { stroke-linecap: round; stroke-width: 11; stroke: var(--grid); transition: stroke .15s; }
#template .seg-line.on { stroke: var(--ink); }
#template .seg-hit { stroke: transparent; stroke-width: 26; cursor: pointer; }
#template .seg-hit:hover + .seg-line:not(.on) { stroke: var(--zero); }
#template .seg-num circle { fill: var(--surface); stroke: var(--line); }
#template .seg-num text { fill: var(--ink-2); font-size: 11px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.digit-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 10px 0; }
.digit-buttons button { padding: 4px 0; }
.digit-buttons button.on { background: var(--ink); color: var(--surface); }
.vec div { display: grid; grid-template-columns: 58px 1fr; gap: 4px; }
.vec code { word-break: break-word; }

/* --- сеть --- */
#net { width: 100%; height: auto; display: block; }
#net .edge { fill: none; transition: opacity .2s; }
#net .node circle { stroke: var(--ink-3); stroke-width: 1; cursor: pointer; }
#net .node.sel circle { stroke: var(--hi); stroke-width: 3; }
#net .node text { font-size: 9.5px; text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--ink); }
#net .node .val { font-size: 10px; }
#net .col-label { font-size: 11px; fill: var(--ink-2); text-anchor: middle; }
#net .layer { transition: opacity .25s; }
#net.phase .layer { opacity: .18; }
#net.phase .layer.lit { opacity: 1; }
#net.dim-edges .edge:not(.sel) { opacity: .08 !important; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.sw { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.sw.neg { background: var(--neg); } .sw.pos { background: var(--pos); } .sw.zero { background: var(--zero); }

/* --- выход --- */
.answer { font-size: 15px; margin-bottom: 8px; }
.answer b { font-size: 26px; vertical-align: middle; margin-left: 4px; }
.bar-row { display: grid; grid-template-columns: 16px 1fr 50px; align-items: center; gap: 8px; height: 24px; }
.bar-row .d { font-weight: 600; text-align: center; }
.bar-row .track { position: relative; height: 14px; background: var(--node-zero); border-radius: 4px; }
.bar-row .track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--ink-3); }
.bar-row .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; transition: all .3s; }
.bar-row .v { font: 12px ui-monospace, Menlo, monospace; text-align: right; color: var(--ink-2); }
.bar-row.win .d { color: var(--surface); background: var(--ink); border-radius: 4px; }
.bar-row.goal .track { outline: 2px dashed var(--hi); outline-offset: 2px; }
.target { display: grid; gap: 4px; margin-top: 12px; font-size: 13px; }
.target select { width: 100%; }
#out-card.flash { outline: 3px solid var(--hi); }

/* --- граф нейрона --- */
.formula { font: 13px ui-monospace, Menlo, monospace; background: var(--bg); padding: 6px 8px; border-radius: 6px; overflow-x: auto; white-space: nowrap; }
.graph-wrap { overflow: auto; max-height: 720px; border: 1px solid var(--line); border-radius: 8px; }
#graph { display: block; }
#graph .box rect { fill: var(--surface); stroke: var(--line); }
#graph .box.op rect { fill: var(--bg); }
#graph .box:hover rect { stroke: var(--hi); stroke-width: 2; }
#graph .box .bar { stroke: none; }
#graph text { font: 11px ui-monospace, Menlo, monospace; fill: var(--ink); dominant-baseline: central; }
#graph text.lbl { fill: var(--ink-2); }
#graph text.g { fill: var(--ink-2); }
#graph .link { fill: none; stroke: var(--ink-3); stroke-width: 1.2; }
#graph .opchar { font-size: 15px; font-weight: 700; text-anchor: middle; }

/* --- обучение --- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stats div { background: var(--bg); border-radius: 8px; padding: 6px 10px; display: flex; flex-direction: column; }
.stats b { font-size: 20px; font-variant-numeric: tabular-nums; }
.controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.controls input { width: 70px; }
.phases { list-style: none; padding: 0; margin: 12px 0 4px; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; counter-reset: ph; }
.phases li { font-size: 11px; background: var(--bg); border-radius: 6px; padding: 5px 6px; color: var(--ink-2); border: 2px solid transparent; }
.phases li b { display: block; color: var(--ink); font-size: 12px; }
.phases li.on { border-color: var(--hi); }
.phases li.done { opacity: .6; }
.phase-text { min-height: 40px; font-size: 13px; }
.chart-wrap { position: relative; }
#chart { width: 100%; height: auto; display: block; }
#chart .grid line { stroke: var(--grid); }
#chart .axis text { font-size: 10px; fill: var(--ink-3); }
#chart .series { fill: none; stroke: var(--pos); stroke-width: 2; }
#chart .cross { stroke: var(--ink-3); stroke-dasharray: 3 3; }
#chart .dot { fill: var(--pos); stroke: var(--surface); stroke-width: 2; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 340px;
  background: var(--ink); color: var(--surface); padding: 7px 9px; border-radius: 8px; font-size: 12px;
}
.chart-wrap .tip { position: absolute; }
.explain ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.explain b { color: var(--ink); }
.net-phase {
  border: 2px solid var(--hi); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px;
  font-size: 13px; background: var(--bg);
}
.net-phase b { margin-right: 6px; }

/* --- навигация по сайту --- */
.site-nav {
  display: flex; gap: 2px; overflow-x: auto; padding: 8px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.site-nav a {
  white-space: nowrap; text-decoration: none; color: var(--ink-2); padding: 5px 10px; border-radius: 8px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.site-nav a:hover { background: var(--bg); color: var(--ink); }
.site-nav a.here { background: var(--ink); color: var(--surface); }
.site-nav .n {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid currentColor; font-size: 10.5px;
}
a { color: var(--accent); }
.net-phase .np-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.net-phase .np-btns { display: inline-flex; gap: 6px; }
.net-phase .np-btns button { padding: 3px 10px; font-size: 13px; }
.net-phase .np-keys { color: var(--ink-3); font-size: 11.5px; margin-top: 4px; }
.phases li { cursor: default; }
body:has(.net-phase:not([hidden])) .phases li { cursor: pointer; }
