/* Mirror Symmetry Resolver. Layout: title with the weight sets; the six-bit board with the truth badge and pattern
   buttons; the two balance scales beside the output beacon and the circuit; then the cancellation engine, the
   experiments and the 64-pattern sweep; then the re-learning run. Changing text has a fixed size, so nothing moves. */
:root {
  color-scheme: dark;
  --bg: #080c14;
  --panel: #0d131e;
  --panel-2: #131b29;
  --line: #1b2536;
  --line-2: #2a3850;
  --fg: #e3e9f3;
  --muted: #8c98ad;
  --dim: #58647a;
  --cyan: #00f5ff;
  --mag: #ff2a6d;
  --amber: #ffb800;
  --green: #34f5a0;
  --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(--cyan); 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(--cyan); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(0,245,255,.07); }
.chip.dim { opacity: .45; }
.note { margin: 0; font-size: 13.5px; color: #c6cfdf; max-width: 130ch; min-height: calc(2 * 1.45em); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 30px; 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(--cyan); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { min-height: 26px; padding: 2px 9px; font-size: 12px; }
.btn.primary { background: rgba(0,245,255,.09); border-color: rgba(0,245,255,.5); color: var(--cyan); }
.btn.mono { font-family: var(--mono); letter-spacing: .04em; }
.btn.mono.on { border-color: var(--green); color: var(--green); }

.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); min-width: 0; }
.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); }
.tag { display: inline-block; white-space: nowrap; font: 500 11.5px/15px var(--mono); min-height: 23px; 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(52,245,160,.5); }
.tag.warn { color: var(--amber); border-color: rgba(255,184,0,.5); }
.tag.bad { color: var(--mag); border-color: rgba(255,42,109,.55); }
canvas { display: block; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #05080e; }

/* board */
.board-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 16px; align-items: center; }
.pads { display: grid; grid-template-columns: repeat(3, 1fr) 14px repeat(3, 1fr); gap: 8px; align-items: stretch; }
.pad { display: grid; place-items: center; gap: 2px; padding: 10px 0 8px; border-radius: 8px; border: 1px solid var(--line-2); background: #0e1522; cursor: pointer; transition: background .1s, box-shadow .1s, border-color .1s; font-family: var(--mono); }
.pad b { font-size: 30px; line-height: 1; font-weight: 700; color: var(--dim); }
.pad span { font-size: 11px; color: var(--dim); }
.pad.on { background: rgba(0,245,255,.16); border-color: var(--cyan); box-shadow: 0 0 18px rgba(0,245,255,.4), inset 0 0 12px rgba(0,245,255,.25); }
.pad.on b { color: var(--cyan); }
.pad.on span { color: #9ff9ff; }
.pads .axis { position: relative; }
.pads .axis::before { content: ""; position: absolute; left: 50%; top: -6px; bottom: -6px; border-left: 2px dashed rgba(255,255,255,.35); }
.pads .axis::after { content: "mirror"; position: absolute; left: 50%; bottom: -20px; transform: translateX(-50%); font: 10px var(--mono); color: var(--dim); }
.board-side { display: grid; gap: 8px; }
.truth { font: 700 13px var(--mono); letter-spacing: .05em; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.truth.sym { color: var(--green); border-color: rgba(52,245,160,.55); background: rgba(52,245,160,.07); }
.truth.asym { color: var(--amber); border-color: rgba(255,184,0,.5); background: rgba(255,184,0,.06); }
.row-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* stage */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
#cvScales { height: 400px; background: radial-gradient(110% 90% at 50% 40%, #0c1527 0%, #04070c 75%); }
.side { display: grid; gap: 12px; min-width: 0; }
.beacon { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: center; }
#cvBeacon { width: 120px; height: 120px; border: 0; background: transparent; }
.b-read { display: grid; gap: 3px; font: 12px var(--mono); color: var(--muted); }
.b-read b { font: 700 15px var(--mono); letter-spacing: .05em; white-space: nowrap; }
.b-read span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bWhy { white-space: normal; height: calc(3 * 1.45em); overflow: hidden; }
#cvCircuit { height: 250px; }

/* lower */
.lower { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
#cvBars { height: 110px; }
.sums { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; font: 11.5px var(--mono); font-variant-numeric: tabular-nums; }
.sums div { display: grid; gap: 1px; padding: 4px 6px; border-radius: 4px; border: 1px solid var(--line); }
.sums div span { color: var(--dim); }
.sums div b { font-weight: 500; }
.sums div.L { border-color: var(--cyan); background: rgba(0,245,255,.08); }
.sums div.R { border-color: var(--mag); background: rgba(255,42,109,.08); }
.sums div.LR { border-color: var(--green); background: rgba(52,245,160,.1); }
.sums div.col b { color: var(--amber); }
#sumsCap { height: calc(2 * 1.45em); overflow: hidden; }
.mag { display: grid; grid-template-columns: 112px minmax(0, 1fr) 46px; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.mag b { font: 500 12px var(--mono); color: var(--cyan); text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); }
.row select { min-height: 26px; font-size: 12px; padding: 1px 4px; }
#expCap { height: calc(3 * 1.45em); overflow: hidden; }
#cvGrid { height: 200px; cursor: pointer; }
.conf { display: grid; grid-template-columns: auto 1fr 1fr; gap: 3px 8px; font: 12px var(--mono); font-variant-numeric: tabular-nums; align-items: center; }
.conf span { color: var(--dim); font-size: 11px; }
.conf b { text-align: center; padding: 3px 0; border-radius: 4px; font-weight: 600; }
.conf .ok { background: rgba(52,245,160,.12); color: var(--green); }
.conf .no { background: rgba(255,42,109,.12); color: var(--mag); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); }

/* relearn */
.sl { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.sl input { width: 100px; }
.sl b { font: 500 12px var(--mono); min-width: 3ch; color: var(--fg); }
.rl-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 12px; align-items: start; }
#cvTrain { height: 150px; }
.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 .good { color: var(--green); } .kv .amb { color: var(--amber); }

@media (max-width: 1200px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .lower { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rl-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  h1 { font-size: 20px; }
  .board-grid, .lower { grid-template-columns: minmax(0, 1fr); }
  #cvScales { height: 320px; }
  .pad b { font-size: 22px; }
  .note { min-height: 0; }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .pad { transition: none; } }
