:root {
  --bg: #0d1017;
  --panel: #161b26;
  --panel2: #1d2431;
  --line: #2a3342;
  --txt: #d7dee9;
  --muted: #8b97a8;
  --cu: #e88a3a;
  --g: #5aa0ff;
  --co: #50e68c;
  --accent: #6ea8fe;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.5 system-ui, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #10141d, #0d1017);
}
header h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
header .sub { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }

main { flex: 1; display: flex; min-height: 0; }

/* Sidebar */
#controls {
  width: 300px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto; padding: 6px 14px 24px;
}
#controls section { padding: 12px 0; border-bottom: 1px solid var(--line); }
#controls h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 6px 0 10px; }
label { display: block; margin: 10px 0; font-size: 13px; }
.hint { color: var(--muted); font-weight: 400; font-size: 11.5px; float: right; }
.row { display: flex; gap: 6px; margin-top: 5px; }
input[type=text], input[type=number], select {
  width: 100%; background: var(--panel2); border: 1px solid var(--line);
  color: var(--txt); border-radius: 7px; padding: 7px 9px; font-size: 13px;
}
select { cursor: pointer; }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 8px 0; }
.chk { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 13px; }
button#reset {
  width: 100%; margin-top: 8px; padding: 8px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--txt);
  cursor: pointer;
}
button#reset:hover { border-color: var(--accent); }

#readout dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 0; }
#readout dt { color: var(--muted); font-size: 12.5px; }
#readout dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#readout details { margin-top: 12px; }
#readout summary { cursor: pointer; color: var(--muted); font-size: 12px; }
#readout table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 12px; }
#readout th, #readout td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); }

/* Stage */
#stage { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; }
.tab {
  background: transparent; border: 1px solid var(--line); border-bottom: none;
  color: var(--muted); padding: 7px 16px; border-radius: 8px 8px 0 0; cursor: pointer;
}
.tab.active { background: var(--panel); color: var(--txt); }
.panel { flex: 1; display: none; min-height: 0; border-top: 1px solid var(--line); }
.panel.active { display: block; }
#view3d { width: 100%; height: 100%; }
#view3d canvas { display: block; }
#cv2d { width: 100%; height: 100%; display: block; cursor: grab; }
#cv2d:active { cursor: grabbing; }

.legend {
  position: absolute; bottom: 12px; left: 12px;
  display: flex; gap: 16px; align-items: center;
  background: rgba(13,16,23,0.8); padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); font-size: 12px;
}
.legend .d { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend .cu { background: var(--cu); }
.legend .g  { background: var(--g); }
.legend .co { background: transparent; border: 2px solid var(--co); }
.legend .tip { color: var(--muted); }

@media (max-width: 820px) {
  main { flex-direction: column; }
  #controls { width: 100%; max-height: 42%; }
}
