/* Two-Phase Hebbian Machine. Layout: title with network presets; the learning-cycle bar; the clamped (day) and
   free-running (night) chambers side by side beside the synapse inspector and settings; then G, the distribution
   match, the weight matrix and the hidden codes. Stacks on narrow screens. */
:root {
  color-scheme: dark;
  --bg: #080b11;
  --panel: #0d121b;
  --panel-2: #131a26;
  --line: #1c2533;
  --line-2: #2a3648;
  --fg: #e4e9f2;
  --muted: #8d98ab;
  --dim: #5a6578;
  --day: #ffb020;
  --night: #8b7cff;
  --co: #39ff88;
  --exc: #6fe7ff;
  --inh: #ff3d6e;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--exc); outline-offset: 2px; }
sub { font-size: .72em; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--exc); }
.chip.on { border-color: var(--exc); color: var(--exc); background: rgba(111,231,255,.07); }
.note { margin: 0; font-size: 13.5px; color: #c7cfdf; max-width: 130ch; }
.note b { color: var(--fg); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 32px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--exc); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.icon { padding: 5px 8px; }
.btn.primary { background: rgba(111,231,255,.1); border-color: rgba(111,231,255,.5); color: var(--exc); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; flex: none; }
.segb { background: var(--panel-2); border: 0; padding: 4px 9px; font: 12px var(--mono); cursor: pointer; color: var(--muted); }
.segb + .segb { border-left: 1px solid var(--line-2); }
.segb.on { background: rgba(111,231,255,.12); color: var(--exc); }

.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; align-content: start; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.cap { margin: 0; font: 11.5px/1.45 var(--mono); color: var(--dim); }
.cap b { color: var(--muted); font-weight: 500; }
.tag { white-space: nowrap; font: 500 11.5px var(--mono); color: var(--muted); padding: 3px 8px; border-radius: 4px; border: 1px solid var(--line-2); font-variant-numeric: tabular-nums; }
canvas { display: block; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #05070c; }

/* learning-cycle bar */
.transport { padding: 8px 12px; }
.tr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.spacer { flex: 1; }
.clock { font: 500 12.5px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 20ch; text-align: right; }
.clock b { color: var(--fg); font-weight: 600; }
.pipe { list-style: none; margin: 0 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.pipe li { display: flex; align-items: center; gap: 7px; padding: 4px 10px; border: 1px solid var(--line-2); border-radius: 4px; font-size: 12.5px; color: var(--muted); background: var(--panel-2); }
.pipe li em { font: 11px var(--mono); font-style: normal; color: var(--dim); }
.pipe li i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.pipe li + li::before { content: ""; width: 10px; height: 1px; background: var(--line-2); margin: 0 6px 0 -14px; }
.pipe li.on { color: var(--fg); }
.pipe li[data-st="day"].on { border-color: rgba(255,176,32,.6); } .pipe li[data-st="day"].on i { background: var(--day); box-shadow: 0 0 8px var(--day); }
.pipe li[data-st="night"].on { border-color: rgba(139,124,255,.6); } .pipe li[data-st="night"].on i { background: var(--night); box-shadow: 0 0 8px var(--night); }
.pipe li[data-st="update"].on { border-color: rgba(57,255,136,.6); } .pipe li[data-st="update"].on i { background: var(--co); box-shadow: 0 0 8px var(--co); }

/* the two chambers */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 12px; align-items: start; }
.arena { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; min-width: 0; }
.chamber { border-top-width: 2px; }
.chamber.day { border-color: rgba(255,176,32,.28); border-top-color: var(--day); }
.chamber.night { border-color: rgba(139,124,255,.28); border-top-color: var(--night); }
.chamber.live.day { box-shadow: 0 0 0 1px rgba(255,176,32,.35), 0 0 22px -8px rgba(255,176,32,.5); }
.chamber.live.night { box-shadow: 0 0 0 1px rgba(139,124,255,.4), 0 0 22px -8px rgba(139,124,255,.6); }
.chamber.day .tag.live { color: var(--day); border-color: rgba(255,176,32,.55); }
.chamber.night .tag.live { color: var(--night); border-color: rgba(139,124,255,.6); }
.chamber canvas { height: 360px; cursor: pointer; }
.chamber.day canvas { background: radial-gradient(110% 90% at 50% 0%, #17120a 0%, #06070b 70%); }
.chamber.night canvas { background: radial-gradient(110% 90% at 50% 0%, #0f0d26 0%, #05060c 70%); }
.ch-foot { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 10px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.ch-foot div { display: grid; gap: 1px; min-width: 0; }
.ch-foot span { color: var(--dim); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-foot b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chamber.day .ch-foot b.k { color: var(--day); }
.chamber.night .ch-foot b.k { color: var(--night); }

/* side column */
.side { display: grid; gap: 12px; min-width: 0; }
.ins { display: grid; gap: 9px; }
.ins-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font: 600 16px var(--mono); }
.ins-title small { font: 400 11.5px var(--mono); color: var(--dim); }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; text-align: right; }
.kv .pos { color: var(--exc); } .kv .neg { color: var(--inh); }
.meter { display: grid; grid-template-columns: 76px minmax(0, 1fr) 52px; gap: 8px; align-items: center; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.meter > span { color: var(--muted); }
.meter > b { text-align: right; font-weight: 500; }
.meter .t { position: relative; height: 12px; border-radius: 3px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.meter .t i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; transition: width .18s; }
.meter .t u { position: absolute; top: -1px; bottom: -1px; width: 2px; background: #fff; opacity: .85; text-decoration: none; }
.meter .t s { position: absolute; top: 2px; bottom: 2px; width: 1px; background: rgba(255,255,255,.35); text-decoration: none; }
.meter.day .t i { background: linear-gradient(90deg, rgba(255,176,32,.5), var(--day)); }
.meter.night .t i { background: linear-gradient(90deg, rgba(139,124,255,.5), var(--night)); }
.verdict { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; align-items: center; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel-2); }
.verdict svg { width: 22px; height: 22px; grid-row: span 2; }
.verdict b { font-size: 13.5px; font-weight: 600; }
.verdict span { font-size: 12px; color: var(--muted); line-height: 1.35; max-height: calc(3 * 1.35em); overflow: hidden; }
.verdict { height: 106px; align-content: center; overflow: hidden; }
.verdict b { line-height: 1.3; }
.kv span, .kv b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ins-title { white-space: nowrap; overflow: hidden; }
#whCap, #gCap, #codeCap, #ctlCap { min-height: calc(2 * 1.45em); }
.verdict.up { border-color: rgba(111,231,255,.5); } .verdict.up b, .verdict.up svg { color: var(--exc); }
.verdict.down { border-color: rgba(255,61,110,.5); } .verdict.down b, .verdict.down svg { color: var(--inh); }
.verdict.wait b, .verdict.wait svg { color: var(--muted); }
.verdict.eq { border-color: rgba(57,255,136,.45); } .verdict.eq b, .verdict.eq svg { color: var(--co); }
canvas.mini { height: 84px; cursor: default; }

.left { display: grid; gap: 12px; min-width: 0; }
.ctl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 22px; align-items: start; }
.cg { display: grid; gap: 7px; min-width: 0; }
.ctl .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.ctl .row b { font: 500 12.5px var(--mono); font-variant-numeric: tabular-nums; color: var(--exc); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--line-2), #4b5d78); }
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--line-2), #4b5d78); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -5px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--exc); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 32px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--exc); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch:has(input:focus-visible) { outline: 2px solid var(--exc); outline-offset: 2px; border-radius: 4px; }

/* diagnostics */
.lower { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: start; }
#cvG, #cvDist, #cvMat { height: 210px; }
#cvMat { cursor: pointer; }
.codes { display: grid; gap: 4px; font: 12.5px var(--mono); font-variant-numeric: tabular-nums; }
.codes .cr { display: grid; grid-template-columns: minmax(0, 1fr) auto 46px; gap: 10px; align-items: center; padding: 3px 6px; border-radius: 4px; }
.codes .cr:nth-child(odd) { background: rgba(255,255,255,.025); }
.codes .cr span { color: var(--day); overflow: hidden; text-overflow: ellipsis; }
.codes .cr b { display: inline-flex; gap: 3px; }
.codes .cr b i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--night); }
.codes .cr b i.on { background: var(--night); box-shadow: 0 0 6px rgba(139,124,255,.7); }
.codes .cr em { font-style: normal; color: var(--muted); text-align: right; }
.codes .cr.clash span { color: var(--inh); }
.tag:empty { display: none; }
.tag.good { color: var(--co); border-color: rgba(57,255,136,.5); }

@media (max-width: 1320px) {
  .lower { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .ctl { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  h1 { font-size: 20px; }
  .arena, .lower { grid-template-columns: minmax(0, 1fr); }
  .chamber canvas { height: 300px; }
  .pipe { margin-left: 0; }
  .pipe li + li::before { display: none; }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .switch i, .switch i::after, .meter .t i { transition: none; } }
