/* zebsdsolve app. One dark theme: neutral greys, one gold accent for "the next thing
   to do", green for done, red for stop. Patterns and maps sit on near-black wells. */
:root {
  color-scheme: dark;
  --well: #0a0a0b;
  --bg: #0f0f11;
  --panel: #151517;
  --card: #19191c;
  --field: #111113;
  --raise: #232327;
  --line: #2b2b30;
  --line-soft: #222226;
  --text: #e6e6e8;
  --muted: #9d9da4;
  --faint: #67676e;
  --accent: #d6b064;
  --accent-hi: #e8c77e;
  --accent-ink: #f6eacd;
  --accent-bg: #2a2316;
  --accent-line: #6b5631;
  --good: #7fbf6e;
  --bad: #d4615f;
  --data: #6a9ec8;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --rail: 336px;
  --bar: 30px;
  --status: 26px;
  --rad: 6px;
  --rad-s: 4px;
  --ctl: 28px;
}
* { box-sizing: border-box; margin: 0; padding: 0; scrollbar-width: thin; scrollbar-color: #34343a transparent; }
::selection { background: #4a3d22; }
html, body { height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
svg { width: 1em; height: 1em; flex: none; }
.grow { flex: 1; }

/* ── controls ── */
button, input, select { font: inherit; color: inherit; background: var(--field); border: 1px solid var(--line); border-radius: var(--rad-s); }
button {
  cursor: pointer; padding: 0 10px; height: var(--ctl); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--raise); border-color: #34343a; white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
button:hover { background: #2c2c31; border-color: #44444b; }
button:active { background: #1e1e22; }
button:disabled { opacity: .38; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.well:focus-visible { outline: 1px solid var(--accent-line); outline-offset: -1px; }
button.primary { background: var(--accent-bg); border-color: var(--accent-line); color: var(--accent-ink); }
button.primary:hover { background: #352b1a; border-color: #86693a; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: var(--raise); border-color: var(--line); }
button.ghost:disabled:hover { color: var(--muted); background: transparent; border-color: transparent; }
button.stop { background: #2a1717; border-color: #6c3535; color: #f0c4c4; }
button.stop:hover { background: #351c1c; border-color: #8a4242; }
button svg { width: 13px; height: 13px; }
input[type="number"], select { height: var(--ctl); width: 100%; padding: 0 8px; font-feature-settings: "tnum"; }
input[type="number"] { font: 12.5px var(--mono); padding-right: 2px; }
input[type="number"]:hover, select:hover { border-color: #3b3b41; }
input:disabled, select:disabled { opacity: .45; }
select { cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; flex: none; cursor: pointer; }
label { color: var(--muted); font-size: 11.5px; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
/* a slider through the slices of a volume: thin, in a caption */
input.slide { -webkit-appearance: none; appearance: none; height: 14px; width: 84px; flex: 0 1 84px; min-width: 40px; padding: 0; border: 0; background: transparent; cursor: ew-resize; }
input.slide::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: #3a3a41; }
input.slide::-webkit-slider-thumb { -webkit-appearance: none; width: 9px; height: 13px; margin-top: -5px; border-radius: 2px; background: var(--accent); border: 0; }
input.slide::-moz-range-track { height: 3px; border-radius: 2px; background: #3a3a41; }
input.slide::-moz-range-thumb { width: 9px; height: 13px; border-radius: 2px; background: var(--accent); border: 0; }
input.slide:disabled { visibility: hidden; }

/* ── frame ── */
.app {
  height: 100%; display: grid;
  grid-template: var(--bar) minmax(0, 1fr) var(--status) / var(--rail) minmax(0, 1fr);
  grid-template-areas: "top top" "rail stage" "status status";
}
.topbar { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); user-select: none; }
.brand { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; letter-spacing: .01em; color: var(--accent-ink); }
.brand svg { width: 16px; height: 16px; color: var(--accent); }
.scan-meta, .adapter { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adapter { color: var(--faint); max-width: 40%; }

.rail { grid-area: rail; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
/* the steps as tabs: numbered, joined by a line, one panel at a time */
.tabs { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px 4px 0; border-bottom: 1px solid var(--line); user-select: none; }
.tabs button { position: relative; height: auto; padding: 2px 0 7px; flex-direction: column; gap: 4px; background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); font-size: 11.5px; }
.tabs button:hover { background: transparent; color: var(--text); }
.tabs button + button::before { content: ""; position: absolute; top: 10px; right: calc(50% + 12px); width: calc(100% - 24px); height: 1px; background: var(--line); }
.tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
.step { width: 17px; height: 17px; border-radius: 50%; background: var(--raise); color: var(--muted); font: 600 10.5px/17px var(--mono); text-align: center; transition: background-color .12s, color .12s; }
.tabs button[data-done="1"] .step { background: #1f2c1c; color: var(--good); }
.tabs button[aria-selected="true"] .step { background: var(--accent-bg); color: var(--accent-ink); box-shadow: 0 0 0 1px var(--accent-line); }
.panels { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 10px; }
.panel { display: flex; flex-direction: column; gap: 9px; }
.panel h4 { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.row { display: flex; gap: 6px; flex-wrap: wrap; }
.row > button { flex: 1 1 auto; }
.row.tight > button { flex: 0 0 auto; }
.hint { color: var(--faint); font-size: 11.5px; line-height: 1.45; }
.readout { color: var(--muted); font: 11.5px/1.5 var(--mono); white-space: pre-wrap; min-height: 0; }
.readout:empty { display: none; }
.sub { border-top: 1px solid var(--line-soft); padding-top: 8px; }
.sub > summary { list-style: none; cursor: pointer; color: var(--muted); font-size: 11.5px; user-select: none; }
.sub > summary::-webkit-details-marker { display: none; }
.sub > summary::before { content: "▸ "; color: var(--faint); }
.sub[open] > summary::before { content: "▾ "; }
.sub > * + * { margin-top: 6px; }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 8px; }
.fields:empty { display: none; }
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > span { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field.toggle { flex-direction: row; align-items: center; gap: 7px; height: var(--ctl); align-self: end; }
.field.toggle > span { color: var(--text); font-size: 12.5px; }
/* a control that does not apply with the settings as they are is dimmed, never hidden: what
   is not in view is taken not to exist */
.field[data-off="1"] { opacity: .4; }
.triple { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
/* while a job runs, the settings it runs with stay as they are (dimmed after a moment: a job
   done at once does not flash the rail) */
.app[data-busy="1"] .panel .fields, .app[data-busy="1"] .row.tight { pointer-events: none; opacity: .55; transition: opacity .15s linear .35s; }

.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; font-size: 12px; }
.facts:empty { display: none; }
.facts dt { color: var(--faint); }
.facts dd { color: var(--text); font-family: var(--mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facts.tall { gap: 2px 12px; }
.facts.tall dd { white-space: normal; overflow-wrap: anywhere; }

.phases { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.phases:empty { display: none; }
.phases li { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 8px; background: var(--field); border: 1px solid var(--line-soft); border-radius: var(--rad-s); cursor: pointer; }
.phases li[aria-selected="true"] { border-color: var(--accent-line); }
.phases .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.phases .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phases .pg { color: var(--muted); font: 11.5px var(--mono); }
.phases button { height: 20px; width: 20px; padding: 0; }
.phases button svg { width: 10px; height: 10px; }

/* ── stage: the map over the dock, the pattern beside both; two bars to drag between them ── */
.stage { grid-area: stage; min-width: 0; min-height: 0; display: grid; background: var(--line);
  grid-template-columns: minmax(280px, 1fr) 5px minmax(200px, min(var(--pat-w, clamp(270px, 19vw, 380px)), calc(100% - 290px)));
  grid-template-rows: minmax(140px, 1fr) 5px minmax(110px, min(var(--dock-h, 41%), calc(100% - 150px)));
  grid-template-areas: "map sv pat" "sh sv pat" "dock sv pat"; }
.pane { background: var(--bg); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.map-pane { grid-area: map; }
.pat-pane { grid-area: pat; }
.dock-pane { grid-area: dock; }
.split { background: var(--panel); position: relative; z-index: 2; transition: background-color .12s; }
.split-h { grid-area: sh; cursor: row-resize; border-block: 1px solid var(--line); }
.split-v { grid-area: sv; cursor: col-resize; border-inline: 1px solid var(--line); }
.split:hover, .split[data-drag="1"] { background: var(--accent-line); }
body[data-resize] { user-select: none; }
body[data-resize="row"] * { cursor: row-resize !important; }
body[data-resize="col"] * { cursor: col-resize !important; }
.pane-bar { min-height: var(--bar); flex: none; display: flex; align-items: center; gap: 4px 10px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); user-select: none; overflow: hidden; }
.ttl { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.meta { color: var(--faint); font: 11.5px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta.cell { color: var(--muted); }
.pat-pane .seg button { padding: 0 7px; }
.seg { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: var(--rad-s); overflow: hidden; }
.seg button { height: 20px; padding: 0 8px; font-size: 11.5px; border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--text); background: var(--raise); }
.seg button[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent-bg); }
.seg button:disabled { opacity: .35; }
.seg button:disabled:hover { color: var(--muted); background: transparent; }

.well { position: relative; flex: 1; min-height: 0; min-width: 0; background: var(--well); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.well canvas { image-rendering: pixelated; max-width: 100%; max-height: 100%; display: block; }
button.mini { height: 20px; padding: 0 8px; font-size: 11.5px; }
/* the map is placed by the app: it zooms and moves inside its well */
#map, #map-over { position: absolute; max-width: none; max-height: none; }
#map { cursor: crosshair; }
#map-well[data-pan="1"] #map { cursor: grabbing; }
.over { position: absolute; pointer-events: none; overflow: visible; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); text-align: center; padding: 20px; }
.app[data-scan="1"] .empty { display: none; }
/* what the map's colours mean, in its corner */
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; max-width: calc(100% - 16px); padding: 4px 7px; border-radius: var(--rad-s);
  background: rgba(15, 15, 17, .82); border: 1px solid var(--line); color: var(--muted); font: 11px var(--mono); cursor: pointer; user-select: none; }
.legend[data-folded="1"] > * { display: none; }
.legend[data-folded="1"]::after { content: "key"; }
.legend .bar { width: 96px; height: 8px; border-radius: 2px; background: linear-gradient(90deg, #000, #fff); border: 1px solid #3a3a41; }
.legend .chip { display: inline-flex; align-items: center; gap: 4px; }
.legend .chip i { width: 9px; height: 9px; border-radius: 2px; display: block; }
.legend canvas { image-rendering: auto; }
.legend .keys { display: flex; align-items: flex-end; }
.legend .key { position: relative; display: block; }
.legend .key span { position: absolute; font-size: 10px; color: var(--text); text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }

/* ── the pattern: three images and their numbers, laid out by the shape the pane has ── */
.pat-pane { container-type: size; }
.pats { flex: 1; min-height: 0; display: grid; gap: 1px; background: var(--line); grid-template: repeat(3, minmax(0, 1fr)) auto / minmax(0, 1fr); }
@container (min-aspect-ratio: 5/8) { .pats { grid-template: repeat(2, minmax(0, 1fr)) / repeat(2, minmax(0, 1fr)); } }
@container (min-aspect-ratio: 2/1) { .pats { grid-template: minmax(0, 1fr) / repeat(3, minmax(0, 1fr)) minmax(190px, .8fr); } }
.pats .facts-cell { background: var(--bg); overflow: auto; padding: 7px 10px; display: flex; flex-direction: column; gap: 6px; max-height: 100%; }
.pats .opts { display: flex; gap: 4px 14px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; border-top: 1px solid var(--line-soft); }
.pats figure { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.pats .well canvas { width: 100%; height: 100%; object-fit: contain; }
.pats figcaption { position: absolute; left: 0; bottom: 0; max-width: 100%; padding: 2px 7px; color: var(--muted); font-size: 11px; background: rgba(10, 10, 11, .72); border-top-right-radius: var(--rad-s); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.pats .well canvas.inset { position: absolute; right: 6px; top: 6px; width: auto; height: auto; max-width: 30%; max-height: 30%; border: 1px solid #55555c; box-shadow: 0 0 0 1px rgba(0, 0, 0, .6); }

/* ── the dock ── */
.dock { flex: 1; min-height: 0; display: flex; }
.votes { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.votes-bar { flex: none; display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; padding: 5px 10px; border-bottom: 1px solid var(--line-soft); }
/* three planes: the x–y slice large, the two slices along z stacked beside it; or every slice
   along one axis in one figure. The profiles and the numbers at the right. */
.votes-grid { flex: 1; min-height: 0; display: grid; grid-template: repeat(2, minmax(0, 1fr)) / minmax(0, 1fr) minmax(0, 1.25fr) minmax(236px, 272px); gap: 1px; background: var(--line); }
.votes-grid figure { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.votes-grid figure.plane:nth-child(1) { grid-column: 1; grid-row: 1 / 3; }
.votes-grid figure.plane:nth-child(2) { grid-column: 2; grid-row: 1; }
.votes-grid figure.plane:nth-child(3) { grid-column: 2; grid-row: 2; }
.votes-grid figure.every { display: none; grid-column: 1 / 3; grid-row: 1 / 3; }
.votes-grid:not([data-mode="planes"]) figure.plane { display: none; }
.votes-grid:not([data-mode="planes"]) figure.every { display: flex; }
.votes-side { grid-column: 3; grid-row: 1 / 3; background: var(--bg); overflow: auto; padding: 6px 10px; display: flex; flex-direction: column; gap: 6px; }
.votes-side > * { flex: none; }
.votes-side .readout { font-size: 10.5px; line-height: 1.45; white-space: pre; }
.votes-side .profiles { height: 96px; cursor: crosshair; }
.votes-side .marks { font-size: 11px; white-space: normal; }
.votes-side .marks .k { font-family: var(--mono); margin-left: 3px; }
.votes-side .profiles canvas { width: 100%; height: 100%; display: block; }
.votes-grid .well canvas { cursor: crosshair; }
.votes-grid figcaption { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 2px 8px; color: var(--faint); font: 11px var(--mono); border-top: 1px solid var(--line-soft); white-space: nowrap; overflow: hidden; }
.votes-grid figcaption span { overflow: hidden; text-overflow: ellipsis; }
.dock-view { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.dock-view > .hint { flex: none; padding: 4px 10px; border-top: 1px solid var(--line-soft); }
.dock-view > .well canvas { width: 100%; height: 100%; object-fit: contain; }
.log { flex: 1; overflow: auto; padding: 8px 10px; font: 11.5px/1.5 var(--mono); color: var(--muted); white-space: pre-wrap; user-select: text; }
.log .t { color: var(--faint); }
.log .err { color: var(--bad); }

/* ── status ── */
.statusbar { grid-area: status; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); user-select: none; }
.status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.err { color: var(--bad); }
.progress { width: 180px; height: 6px; border-radius: 3px; background: var(--raise); overflow: hidden; flex: none; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.compile { color: var(--faint); font: 11.5px var(--mono); }
.statusbar .stop svg { width: 10px; height: 10px; }
.app[data-busy="1"] .act, .app[data-busy="1"] #btn-open, .app[data-busy="1"] #btn-example, .app[data-busy="1"] #btn-phase, .app[data-busy="1"] .phases button { opacity: .38; pointer-events: none; transition: opacity .15s linear .35s; }

.dropveil { position: fixed; inset: 0; background: rgba(10, 10, 11, .82); display: flex; align-items: center; justify-content: center; z-index: 10; }
.dropveil > div { border: 2px dashed var(--accent-line); border-radius: 12px; padding: 40px 56px; color: var(--accent-ink); font-size: 15px; max-width: 70%; text-align: center; }

/* a narrow window: the panes one under another, as tall as they come */
@media (max-width: 1100px) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "map" "pat" "dock"; gap: 1px; }
  .split { display: none; }
}
