/* Hinton Diagrams. Layout: title with the three encoders; the preset bar with its note; the recursive diagram beside
   the lens, the editor and the silent-code experiment; then the weight distribution and the hidden codes. Changing
   text has a fixed size, so nothing moves while you hover or edit. */
:root {
  color-scheme: dark;
  --bg: #0c1017;
  --panel: #111723;
  --panel-2: #172031;
  --line: #1e293b;
  --line-2: #2c3a52;
  --fg: #e6ebf3;
  --muted: #8d99ae;
  --dim: #5b677d;
  --white: #ffffff;
  --black: #020617;
  --mid: #4a5568;
  --accent: #fde047;
  --cyan: #67e8f9;
  --red: #f87171;
  --green: #4ade80;
  --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, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.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(--fg); }
.chip.on { border-color: var(--white); color: var(--white); background: rgba(255,255,255,.07); }

.btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 10px; min-height: 32px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--fg); }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--line-2); }
.btn.sm { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.btn.primary { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.55); }
.btn.on { border-color: var(--white); background: rgba(255,255,255,.1); }

.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 { min-width: 0; 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; }
.cap .k { font-size: 13px; }
.k.w { color: #cbd5e1; } .k.b { color: var(--cyan); } .k.s { color: var(--accent); }
.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; }
.tag:empty { visibility: hidden; }
.tag.good { color: var(--green); border-color: rgba(74,222,128,.5); }
.tag.warn { color: var(--accent); border-color: rgba(253,224,71,.5); }
.tag.bad { color: var(--red); border-color: rgba(248,113,113,.5); }
#runTag { min-width: 25ch; text-align: center; }
#silSub, #edSub, #lensSub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
canvas { display: block; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #080b11; }

/* presets */
.tr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.spacer { flex: 1; }
.pre-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.pre-btns .btn em { font: 11px var(--mono); font-style: normal; color: var(--dim); }
.pre-note { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: calc(2 * 1.45em); font-size: 13px; color: #c9d1de; }
.pre-note b { font-weight: 600; margin-right: 10px; }

/* stage */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
.stage-wrap { position: relative; }
#cvDiag { height: 620px; cursor: crosshair; background: #0a0e15; }
.tip { position: absolute; z-index: 2; pointer-events: none; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--line-2); background: rgba(10,14,21,.96); font: 12px/1.5 var(--mono); white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.55); }
.tip b { color: var(--accent); font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 12.5px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 30px; height: 17px; 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: 11px; height: 11px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(13px); background: #1a1a1a; }

/* side */
.side { display: grid; gap: 12px; min-width: 0; }
#cvLens { height: 190px; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv b { font-weight: 500; text-align: right; white-space: nowrap; }
.kv .pos { color: var(--white); } .kv .neg { color: #94a3b8; } .kv .acc { color: var(--accent); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row b { font: 500 12.5px var(--mono); color: var(--accent); font-variant-numeric: tabular-nums; }
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, #020617, #4a5568 50%, #ffffff); border: 1px solid var(--line-2); }
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, #020617, #4a5568 50%, #ffffff); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -6px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
input[type=range]:disabled { opacity: .4; }
#edCap { height: calc(2 * 1.45em); overflow: hidden; }
.sil-units { display: flex; gap: 6px; align-items: center; font: 11px var(--mono); color: var(--muted); min-height: 30px; flex-wrap: wrap; }
.sil-units .grp { display: inline-flex; gap: 4px; align-items: center; padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; }
.sil-units i { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #64748b; font: 700 9px/13px var(--mono); font-style: normal; text-align: center; color: #0c1017; }
.sil-units i.on { background: var(--white); border-color: var(--white); box-shadow: 0 0 8px rgba(255,255,255,.7); }
.sil-units i.tgt { border-color: var(--accent); }
.sil-units i.off-h { background: var(--black); border-color: #64748b; }
.meter { display: grid; grid-template-columns: 82px minmax(0, 1fr) 52px; gap: 8px; align-items: center; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.meter > span { color: var(--muted); white-space: nowrap; }
.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; background: linear-gradient(90deg, #64748b, #ffffff); transition: width .2s; }
.row-btns { display: flex; flex-wrap: wrap; gap: 6px; }
#silCap { height: calc(3 * 1.45em); overflow: hidden; }

/* lower */
.lower { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 12px; align-items: start; }
#cvHist { height: 200px; }
.codes { display: grid; gap: 3px; font: 12.5px var(--mono); font-variant-numeric: tabular-nums; }
.codes .cr { display: grid; grid-template-columns: 82px auto minmax(0, 1fr) 54px 44px; gap: 10px; align-items: center; padding: 3px 7px; border-radius: 4px; border: 1px solid var(--line); }
.codes .cr span { color: var(--muted); white-space: nowrap; }
.codes .cr .bits { display: inline-flex; gap: 4px; }
.codes .cr .bits i { width: 12px; height: 12px; border: 1px solid #94a3b8; background: var(--black); }
.codes .cr .bits i.on { background: var(--white); border-color: var(--white); }
.codes .cr code { font: inherit; }
.codes .cr small { color: var(--accent); font-size: 11px; text-align: right; }
.codes .cr em { font-style: normal; color: var(--dim); text-align: right; }
.codes .cr.clash { border-color: rgba(253,224,71,.5); background: rgba(253,224,71,.06); }
.codes .cr.silent { border-color: rgba(255,255,255,.4); }

/* dialog */
dialog { border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel); color: var(--fg); padding: 0; width: min(760px, 94vw); }
dialog::backdrop { background: rgba(2,6,23,.7); }
.dlg { display: grid; gap: 10px; padding: 16px; }
.dlg h3 { margin: 0; font: 600 18px var(--display); }
.dlg textarea { width: 100%; height: 340px; resize: vertical; background: #080b11; border: 1px solid var(--line-2); border-radius: 6px; padding: 10px; font: 12px/1.45 var(--mono); color: var(--fg); }
.err { margin: 0; min-height: 1.45em; font: 12px var(--mono); color: var(--red); }

@media (max-width: 1150px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
  .lower { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  h1 { font-size: 20px; }
  #cvDiag { height: 440px; }
  .pre-note { -webkit-line-clamp: 4; height: calc(4 * 1.45em); }
}
.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; } }
