/* Booling — styles.css
 * Desktop-first. Dark by default, light on request or system preference. */

:root {
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #1b212b;
  --panel-3: #212936;
  --line: #262f3d;
  --line-soft: #1e2632;
  --text: #e7ebf2;
  --muted: #8a94a8;
  --faint: #5c667a;
  --accent: #7aa2ff;
  --accent-soft: rgba(122, 162, 255, 0.14);
  --true: #45d483;
  --true-soft: rgba(69, 212, 131, 0.13);
  --false: #ff7a7a;
  --false-soft: rgba(255, 122, 122, 0.12);
  --skip: #4d5769;
  --skip-soft: rgba(77, 87, 105, 0.16);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  --radius: 10px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --panel-3: #eef2f8;
  --line: #dde3ec;
  --line-soft: #e8edf4;
  --text: #17202e;
  --muted: #5f6c81;
  --faint: #97a1b2;
  --accent: #3560d8;
  --accent-soft: rgba(53, 96, 216, 0.10);
  --true: #12924f;
  --true-soft: rgba(18, 146, 79, 0.11);
  --false: #cf2e2e;
  --false-soft: rgba(207, 46, 46, 0.09);
  --skip: #a9b3c4;
  --skip-soft: rgba(169, 179, 196, 0.18);
  --shadow: 0 12px 30px rgba(23, 32, 46, 0.10);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex: 0 0 auto;
  user-select: none;
}
.brand b {
  font-size: 17px;
  letter-spacing: -0.3px;
  font-weight: 650;
}
.brand span {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.editor { flex: 1 1 auto; min-width: 0; }

.input-wrap { position: relative; }

#formula {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 15px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
#formula:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#formula.invalid { border-color: var(--false); }

/* Monospace ruler that positions the caret under the offending token. */
.error-ruler {
  position: absolute;
  left: 12px;
  top: 100%;
  margin-top: 1px;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--false);
  white-space: pre;
  pointer-events: none;
  line-height: 1;
}

.palette {
  display: flex;
  gap: 4px;
  margin-top: 7px;
  flex-wrap: wrap;
}
.palette button {
  min-width: 30px;
  height: 26px;
  padding: 0 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  transition: all .12s;
}
.palette button:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.topbar-actions { display: flex; gap: 7px; flex: 0 0 auto; align-self: flex-start; }

.btn {
  height: 34px;
  padding: 0 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  transition: all .12s;
  white-space: nowrap;
}
.btn:hover { color: var(--text); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { height: 27px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn.active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

/* ---- status strip ---- */

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 18px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  min-height: 36px;
  font-size: 12.5px;
  overflow-x: auto;
  scrollbar-width: none;
}
.status::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  background: var(--panel-3);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.good b { color: var(--true); }
.chip.bad b { color: var(--false); }
.chip.warn { border-color: var(--false); color: var(--false); }

.status .err {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--false);
  font-family: var(--mono);
  font-size: 12.5px;
}

/* ---- workspace ---- */

.workspace {
  display: grid;
  grid-template-columns: 296px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px;
}
.card > h3 {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.row-stepper .idx {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.row-stepper .idx b { color: var(--text); }
.step-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
}
.step-btn:hover { color: var(--accent); border-color: var(--accent); }

.vars { display: flex; flex-direction: column; gap: 6px; }
.var-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}
.var-row .name {
  font-family: var(--mono);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.var-row .name.dim { color: var(--faint); text-decoration: line-through; }
.toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--panel-3);
}
.toggle button {
  width: 30px; height: 25px;
  border: 0; background: transparent;
  color: var(--faint);
  font-family: var(--mono); font-size: 12px;
}
.toggle button.on:first-child { background: var(--false-soft); color: var(--false); font-weight: 700; }
.toggle button.on:last-child { background: var(--true-soft); color: var(--true); font-weight: 700; }

.verdict {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 13px;
}
.verdict .val { font-size: 20px; font-weight: 700; }
.verdict.t .val { color: var(--true); }
.verdict.f .val { color: var(--false); }

.playbar { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.playbar input[type=range] { flex: 1; accent-color: var(--accent); }
.playbar .count { font-family: var(--mono); font-size: 11px; color: var(--faint); min-width: 44px; text-align: right; }

.hintline {
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 8px;
  line-height: 1.4;
}
.hintline code {
  font-family: var(--mono);
  color: var(--muted);
  background: var(--panel-3);
  padding: 1px 4px;
  border-radius: 4px;
}

.order-list { display: flex; flex-wrap: wrap; gap: 5px; }
.order-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: grab;
  user-select: none;
}
.order-chip:hover { border-color: var(--accent); }
.order-chip.dragging { opacity: .4; }
.order-chip .lv { color: var(--faint); font-size: 10px; }

/* ---- content ---- */

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.tab {
  position: relative;
  padding: 10px 14px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: color .12s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab kbd {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--faint);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 6px;
}

.panes { flex: 1 1 auto; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; }
.pane.active { display: flex; }
.pane-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view-host, .block-host { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.block-host > .empty { flex: 1 1 auto; }
.is-hidden { display: none !important; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
  flex: 0 0 auto;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }
.toolbar .label {
  font-size: 11.5px;
  color: var(--faint);
  letter-spacing: .2px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar .label b { color: var(--text); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.segmented button {
  padding: 4px 10px;
  background: var(--panel-2);
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
  padding: 30px;
  line-height: 1.7;
}

/* ---- truth table ---- */

.tt-scroll { flex: 1 1 auto; overflow: auto; position: relative; }

.tt-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  width: max-content;
  min-width: 100%;
}
.tt-th {
  padding: 7px 6px 5px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  border-right: 1px solid var(--line-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  user-select: none;
}
.tt-th:hover { color: var(--text); background: var(--panel-3); }
.tt-th.kind-var { color: var(--accent); }
.tt-th.kind-root { color: var(--text); font-weight: 700; border-left: 2px solid var(--accent); }
.tt-th.sel { background: var(--accent-soft); color: var(--text); }
.tt-th .bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  background: var(--skip);
  opacity: .8;
}

.tt-body { position: relative; width: max-content; min-width: 100%; }
.tt-window { position: absolute; left: 0; right: 0; top: 0; }

.tt-row {
  display: grid;
  height: 26px;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.tt-row:hover { background: var(--panel-2); }
.tt-row.current { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.tt-cell {
  text-align: center;
  font-family: var(--mono);
  font-size: 12.5px;
  border-right: 1px solid var(--line-soft);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tt-cell.v1 { color: var(--true); }
.tt-cell.v0 { color: var(--false); }
.tt-cell.vx { color: var(--skip); background: var(--skip-soft); }
.tt-cell.sel { background: var(--accent-soft); }
.tt-cell.root { border-left: 2px solid var(--accent); font-weight: 700; }
.tt-th.filler, .tt-cell.filler { border-right: 0; cursor: default; }
.tt-th.filler:hover { background: none; }

/* ---- shared svg canvas ---- */

.canvas-wrap { flex: 1 1 auto; overflow: hidden; position: relative; background: var(--bg); }
.canvas-wrap svg { display: block; width: 100%; height: 100%; cursor: grab; }
.canvas-wrap svg.panning { cursor: grabbing; }

.canvas-hint {
  position: absolute;
  right: 12px; bottom: 10px;
  font-size: 11px;
  color: var(--faint);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 3px 8px;
  pointer-events: none;
}

.legend {
  position: absolute;
  left: 12px; bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 5px 10px;
  pointer-events: none;
}
.legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--muted); vertical-align: middle; margin-right: 4px; }
.legend i.dashed { border-top-style: dashed; }
.legend b { color: var(--text); font-weight: 600; }

.tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  box-shadow: var(--shadow);
  max-width: 300px;
  line-height: 1.5;
}
.tip .t { font-family: var(--mono); color: var(--text); }
.tip .s { color: var(--muted); font-size: 11.5px; }

/* svg node styling */
.n-box { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.n-box.t { fill: var(--true-soft); stroke: var(--true); }
.n-box.f { fill: var(--false-soft); stroke: var(--false); }
.n-box.x { fill: transparent; stroke: var(--skip); stroke-dasharray: 4 3; }
.n-box.pending { fill: transparent; stroke: var(--line); opacity: .45; }
.n-box.sel { stroke: var(--accent); stroke-width: 2.5; }
.n-glyph { font-family: var(--mono); font-size: 15px; font-weight: 700; fill: var(--text); text-anchor: middle; }
.n-glyph.x, .n-sub.x { fill: var(--skip); }
.n-glyph.pending, .n-sub.pending { opacity: .45; }
.n-sub { font-family: var(--mono); font-size: 9.5px; fill: var(--muted); text-anchor: middle; }
.n-edge { stroke: var(--line); stroke-width: 1.6; fill: none; }
.n-edge.x { stroke: var(--skip); stroke-dasharray: 4 3; }
.n-edge.pending { opacity: .35; }
.n-edge.live { stroke: var(--accent); stroke-width: 2.2; }
.n-tag { font-family: var(--sans); font-size: 9px; fill: var(--skip); text-anchor: middle; }
.n-share { stroke-width: 0; }
.g-node { cursor: pointer; }

/* bdd */
.b-node { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
.b-node.on { stroke: var(--accent); stroke-width: 2.6; fill: var(--accent-soft); }
.b-term { stroke-width: 1.5; }
.b-term.t { fill: var(--true-soft); stroke: var(--true); }
.b-term.f { fill: var(--false-soft); stroke: var(--false); }
.b-label { font-family: var(--mono); font-size: 12.5px; fill: var(--text); text-anchor: middle; dominant-baseline: central; }
.b-edge { fill: none; stroke: var(--line); stroke-width: 1.5; }
.b-edge.low { stroke-dasharray: 5 4; }
.b-edge.on { stroke: var(--accent); stroke-width: 2.6; stroke-dasharray: none; }
.b-level { font-family: var(--mono); font-size: 10.5px; fill: var(--faint); }
.b-rule { stroke: var(--line-soft); stroke-width: 1; stroke-dasharray: 2 5; }

/* ---- karnaugh ---- */

.kmap-wrap { flex: 1 1 auto; overflow: auto; padding: 22px; }
.kmaps { display: flex; gap: 40px; flex-wrap: wrap; align-items: flex-start; }
.k-cell { fill: var(--panel-2); stroke: var(--line); stroke-width: 1; }
.k-cell.one { fill: var(--true-soft); }
.k-cell.cur { stroke: var(--accent); stroke-width: 2.5; }
.k-val { font-family: var(--mono); font-size: 14px; text-anchor: middle; dominant-baseline: central; }
.k-val.one { fill: var(--true); font-weight: 700; }
.k-val.zero { fill: var(--faint); }
.k-axis { font-family: var(--mono); font-size: 11px; fill: var(--muted); }
.k-axis.head { fill: var(--accent); font-size: 11.5px; }
.k-group { fill: none; stroke-width: 2.5; rx: 9; }
.k-title { font-family: var(--mono); font-size: 12px; fill: var(--muted); }

.k-legend { display: flex; flex-direction: column; gap: 7px; margin-top: 20px; }
.k-legend .item { display: flex; align-items: center; gap: 9px; font-family: var(--mono); font-size: 12.5px; }
.k-legend .swatch { width: 15px; height: 15px; border-radius: 4px; border: 2.5px solid; flex: 0 0 auto; }
.k-legend .ess { font-family: var(--sans); font-size: 10px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }

/* ---- minimal form panel ---- */

.min-wrap { flex: 1 1 auto; overflow-y: auto; padding: 20px; }
.min-grid { display: grid; gap: 14px; max-width: 980px; }
.form-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px 16px;
}
.form-card h4 {
  margin: 0 0 9px;
  font-size: 10.5px;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-card .formula {
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.6;
  word-break: break-word;
  color: var(--text);
}
.form-card .meta {
  margin-top: 9px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.delta { font-weight: 600; font-family: var(--mono); }
.delta.better { color: var(--true); }
.delta.worse { color: var(--false); }
.delta.same { color: var(--muted); }

.pi-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 4px; }
.pi-table th {
  text-align: left;
  font-size: 10.5px;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}
.pi-table td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); font-family: var(--mono); }
.pi-table tr.used td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.pi-table td.dim { color: var(--faint); }
.badge {
  font-family: var(--sans);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.ess { border-color: var(--accent); color: var(--accent); }
.badge.on { border-color: var(--true); color: var(--true); }

.note {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}
.note b { color: var(--text); }
.note.warn { border-color: var(--false); color: var(--false); }

/* ---- popovers ---- */

.popover {
  position: absolute;
  z-index: 50;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  max-height: 70vh;
  overflow-y: auto;
}
.popover.wide { width: 520px; padding: 16px 18px; }
.popover .ex {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
}
.popover .ex:hover { background: var(--accent-soft); }
.popover .ex small { display: block; font-family: var(--sans); color: var(--faint); font-size: 11px; margin-top: 1px; }

.syntax-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.syntax-table td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.syntax-table td:first-child { font-family: var(--mono); color: var(--accent); white-space: nowrap; width: 42%; }
.syntax-table h5 { margin: 14px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--faint); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }
