:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  background: #eef2f6;
  color: #202a35;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }

.app-header {
  height: 66px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid #d4dce5;
}
.app-header h1 { margin: 0; font-size: 20px; letter-spacing: 0; }
.status { margin: 2px 0 0; color: #617083; font-size: 12px; }

button {
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid #b7c2cf;
  border-radius: 5px;
  background: #fff;
  color: #263442;
  cursor: pointer;
}
button:hover { background: #edf3f8; border-color: #7d8fa2; }
button:disabled { cursor: default; color: #94a0ad; background: #edf0f3; }
button.primary { color: #fff; background: #1769aa; border-color: #1769aa; font-weight: 600; }
button.primary:hover { background: #11588f; }
.language-button { min-width: 82px; }

.workspace {
  height: calc(100vh - 66px);
  display: grid;
  grid-template-columns: minmax(390px, 1.15fr) minmax(450px, 0.95fr);
  gap: 1px;
  background: #ccd5df;
}
.disk-workspace, .control-workspace { min-width: 0; background: #f7f9fc; }
.disk-workspace { display: grid; grid-template-rows: minmax(300px, 1fr) auto auto; padding: 16px; }
#encoderCanvas { width: 100%; height: 100%; min-height: 300px; touch-action: none; }
.disk-angle { text-align: center; font: 700 18px Consolas, monospace; padding: 6px; }
.preset-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 8px; }
.preset-row span { margin-right: 4px; color: #566577; }

.control-workspace { display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; overflow-x: auto; flex: 0 0 auto; background: #e6ebf1; border-bottom: 1px solid #c8d1dc; }
.tab { border: 0; border-right: 1px solid #d0d8e1; border-radius: 0; white-space: nowrap; background: transparent; }
.tab.active { background: #fff; color: #145d96; box-shadow: inset 0 -3px #1769aa; font-weight: 600; }
.tab-panel { display: none; overflow-y: auto; height: 100%; padding: 12px; background: #f7f9fc; }
.tab-panel.active { display: block; }
.tabs, #innerBias, #outerBias, #calibration { display: none; }
#live { display: block; }
#live > #test.embedded-test { display: block; height: auto; overflow: visible; padding: 0; margin-top: 12px; }

fieldset { margin: 0 0 12px; padding: 14px 12px 12px; border: 1px solid #d2dbe5; border-radius: 6px; background: #fff; }
legend { padding: 0 5px; font-weight: 700; color: #344557; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.form-grid label { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(92px, 0.72fr); align-items: center; gap: 8px; }
input, select { width: 100%; height: 32px; min-width: 0; padding: 4px 7px; background: #fff; border: 1px solid #b8c4d0; border-radius: 4px; }
input:focus, select:focus { outline: 2px solid #9dc7e8; border-color: #1769aa; }

.value-grid { display: grid; grid-template-columns: 1fr auto; margin: 0; gap: 0; }
.value-grid dt, .value-grid dd { margin: 0; padding: 5px 7px; border-bottom: 1px solid #edf0f4; }
.value-grid dd { text-align: right; font-family: Consolas, monospace; }
.value-grid .error-value { color: #c83349; font-weight: 700; }
.coil-table { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1px; background: #e4e9ef; }
.coil-table > * { padding: 6px 8px; background: #fff; text-align: right; font-family: Consolas, monospace; }
.coil-table > :nth-child(3n + 1) { text-align: left; font-family: inherit; }
pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.65 Consolas, "Microsoft YaHei UI", monospace; }
.chart-canvas { display: block; width: 100%; height: 230px; background: #fff; }
.error-chart { height: 310px; }

.bias-panel .help, .help { margin: 0 0 12px; color: #5f6f80; line-height: 1.6; }
.bias-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.bias-grid label { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 10px; }
.command-row, .toggle-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.toggle-row label { display: flex; align-items: center; gap: 6px; margin-right: 15px; }
.toggle-row input { width: 17px; height: 17px; }
.table-wrap { max-height: 320px; overflow: auto; border: 1px solid #d1dae4; background: #fff; }
table { width: 100%; border-collapse: collapse; font-family: Consolas, monospace; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid #e5eaf0; }
th { position: sticky; top: 0; background: #eaf0f5; color: #3a4a5a; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #ddecf7; }
.summary { color: #46586a; line-height: 1.6; }

@media (max-width: 900px) {
  .workspace { height: auto; min-height: calc(100vh - 66px); grid-template-columns: 1fr; grid-template-rows: minmax(430px, 58vh) minmax(600px, auto); }
  .control-workspace { min-height: 650px; }
}
@media (max-width: 560px) {
  .app-header { padding: 8px 10px; }
  .app-header h1 { font-size: 17px; }
  .workspace { grid-template-rows: minmax(390px, 54vh) minmax(650px, auto); }
  .disk-workspace { padding: 8px; }
  .form-grid, .bias-grid { grid-template-columns: 1fr; }
  .preset-row button { flex: 1; min-width: 54px; }
  .tab-panel { padding: 8px; }
}
