:root {
  /* Colours from the Arakis look: desert floor at night, pale sand text, three earth colours, water for what is ready. */
  --bg: #0c0805;       /* page */
  --panel: #150e08;    /* side panels, controls */
  --sunk: #0a0603;     /* canvases, inputs, the top bar */
  --band: #100a06;
  --rule: #4a3320;     /* hairlines */
  --text: #f4e6cf;
  --muted: #b39a78;
  --on: #0c0805;       /* text on a coloured fill */
  --ok: #8fd0ff;       /* water: the primary action, ground steel, an apexed edge */
  --gold: #e0aa1e;     /* sand gold: headings, the burr */
  --spice: #d46322;    /* spice: steel removed, the focus ring */
  --sage: #8fa68e;
  --hot: #fff1d6;      /* white heat: the selected cross-section, running, errors */
  --f-head: Bahnschrift, "DIN Alternate", "Avenir Next Condensed", "Arial Narrow", sans-serif;
  --f-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --f-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--f-body);
  display: flex;
  flex-direction: column;
}

h1, h2, legend, button, .seg span {
  font-family: var(--f-head);
  font-weight: 600;
  letter-spacing: 0.01em;
}
h1 { font-size: 21px; margin: 0; }
h2 { font-size: 16px; margin: 0; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--rule);
  background: var(--band);
}
.tally { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 0; }
.tally div { display: flex; flex-direction: column; align-items: flex-end; }
.tally dt { color: var(--muted); font-size: 12px; }
.tally dd { margin: 0; font: 600 17px var(--f-mono); }

.bench {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 430px;
}
.controls, .inspect { overflow-y: auto; background: var(--panel); }
.controls { border-right: 1px solid var(--rule); padding: 6px 16px 20px; }
.sec-head h2 { white-space: nowrap; }
.inspect { border-left: 1px solid var(--rule); padding: 14px 16px 20px; display: flex; flex-direction: column; gap: 10px; }

fieldset { border: 0; border-top: 1px solid var(--rule); margin: 14px 0 0; padding: 0; }
fieldset:first-child { border-top: 0; margin-top: 4px; }
legend { padding: 10px 0 8px; font-size: 16px; color: var(--gold); }

.note, .hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

/* segmented radio groups */
.seg { display: flex; margin: 0 0 10px; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block; text-align: center; padding: 7px 3px; font-size: 13.5px;
  color: var(--muted); background: var(--sunk); border-right: 1px solid var(--rule); white-space: nowrap;
}
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--text); color: var(--on); }
.seg input:focus-visible + span { outline: 2px solid var(--spice); outline-offset: -2px; }
.seg-wrap { display: grid; grid-template-columns: repeat(4, 1fr); }
.seg-wrap label:nth-child(4) span { border-right: 0; }
.seg-wrap label:nth-child(-n+4) span { border-bottom: 1px solid var(--rule); }
.seg-wrap label:last-child { grid-column: span 2; }

.slider { display: grid; grid-template-columns: 1fr auto; align-items: baseline; margin: 10px 0 0; }
.slider output { font: 13px var(--f-mono); color: var(--text); }
.slider input { grid-column: 1 / -1; width: 100%; margin: 4px 0 0; accent-color: var(--text); }

.pick { display: grid; gap: 4px; margin: 2px 0 0; }
.pick + .slider, .pick + .pick { margin-top: 10px; }
.check-row { margin: 10px 0 0; }
.dish-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 10px 0 0; }
.dish-row .check { margin-right: 0; }
.dish-row button { padding: 5px 8px; font-size: 13px; }
.pick.inline { grid-template-columns: auto auto; align-items: center; gap: 8px; margin: 0; }
.pick.inline span { font-family: var(--f-head); font-weight: 600; font-size: 15px; }
select {
  background: var(--sunk); color: var(--text); border: 1px solid var(--rule); border-radius: 3px;
  padding: 6px 8px; font: 14px var(--f-body);
}

button {
  white-space: nowrap;
  background: var(--sunk); color: var(--text); border: 1px solid var(--rule); border-radius: 3px;
  padding: 7px 10px; font-size: 14px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, input[type=range]:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--spice); outline-offset: 2px;
}
button.primary { background: var(--ok); color: var(--on); border-color: var(--ok); }
button.primary.on { background: var(--hot); border-color: var(--hot); color: var(--on); }
.runrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.runrow .primary { grid-column: 1 / -1; padding: 9px 10px; font-size: 15px; }
#reset { width: 100%; margin-top: 14px; }

/* centre column */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--sunk); }
.stage-tools { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; padding: 10px 14px 0; }
.stage-tools .btns { flex-wrap: wrap; justify-content: flex-end; }
.stage-tools .seg { margin: 0; min-width: 270px; }
.btns { display: flex; gap: 6px; align-items: center; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-right: 6px; white-space: nowrap; cursor: pointer; }
.check input { accent-color: var(--text); }
#gl { flex: 1; min-height: 0; width: 100%; display: block; cursor: grab; touch-action: none; }
#gl:active { cursor: grabbing; }
.hint { padding: 0 14px 8px; margin: 0; }

.edgemap { border-top: 1px solid var(--rule); background: var(--panel); padding: 10px 14px 14px; }
.edgemap-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.legend { display: flex; align-items: center; gap: 8px; font: 12px var(--f-mono); color: var(--muted); }
.legend span { white-space: nowrap; }
.legend i { display: block; width: 120px; height: 8px; border-radius: 1px; flex-shrink: 0; }
.edgemap-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }
#edgemap { width: 100%; height: 30px; display: block; cursor: pointer; touch-action: none; }

/* right column */
.inspect { min-width: 0; }
.sec-head, .chart-head { flex-wrap: wrap; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#st-pos { font: 13px var(--f-mono); color: var(--hot); margin-left: 6px; }
.section-wrap { border: 1px solid var(--rule); position: relative; }
#apex3d { width: 100%; height: clamp(220px, 31vh, 400px); display: none; cursor: grab; touch-action: none; }
#apex-scale { display: none; position: absolute; left: 8px; bottom: 8px; margin: 0; padding: 3px 7px; background: rgba(10, 6, 3, 0.85); font: 12px var(--f-mono); }
.section-wrap.is-3d #section { display: none; }
.section-wrap.is-3d #apex3d, .section-wrap.is-3d #apex-scale { display: block; }
.sec-head .seg { margin: 0; }
.sec-head .seg span { padding: 6px 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.note.bad { color: var(--hot); }
.only-3d { display: none; margin-left: auto; }
.inspect:has(.is-3d) .only-3d { display: block; }
.inspect:has(.is-3d) .only-2d { display: none; }
.only-3d .check { margin: 0; font-size: 12.5px; }
#section { width: 100%; height: clamp(220px, 31vh, 400px); display: block; cursor: crosshair; touch-action: none; }
.key { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; font-size: 12.5px; color: var(--muted); }
.key i { display: inline-block; width: 12px; height: 4px; margin-right: 6px; vertical-align: middle; }
.k-ground { background: var(--ok); }
.k-removed { background: var(--spice); opacity: 0.6; height: 10px !important; }
.k-burr { background: var(--gold); }
.k-apex { background: var(--ok); }

.verdict {
  margin: 2px 0 0; padding: 9px 12px; background: var(--sunk);
  border-left: 3px solid var(--muted); font-size: 14px; max-width: 62ch;
}
.verdict.good { border-left-color: var(--ok); }
.verdict.burr { border-left-color: var(--gold); }

.readout { margin: 0; display: grid; grid-template-columns: 1fr auto; }
.readout dt, .readout dd { padding: 3px 0; border-bottom: 1px solid rgba(74, 51, 32, 0.6); }
.readout dt { color: var(--muted); }
.readout dd { margin: 0; text-align: right; font: 13px var(--f-mono); }
.chart-head { margin-top: 6px; }
#chart { width: 100%; height: 124px; display: block; flex: none; }

@media (max-width: 1180px) {
  body { height: auto; }
  .bench { grid-template-columns: 1fr; }
  .controls, .inspect { border: 0; border-top: 1px solid var(--rule); overflow: visible; }
  .stage { order: -1; }
  #gl { height: 52vh; flex: none; }
  .stage-tools { flex-wrap: wrap; }
  .bar { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .tally { gap: 8px 18px; }
  .tally div { align-items: flex-start; }
  .stage-tools .seg { min-width: 0; width: 100%; }
  .legend i { width: clamp(64px, 24vw, 120px); }
}
