:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #15181b;
  color: #eef4f2;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  height: 100vh;
  min-height: 620px;
  background: #15181b;
}

.viewport-pane {
  position: relative;
  min-width: 0;
  background: radial-gradient(circle at 50% 38%, #293036 0, #181d21 42%, #111416 100%);
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

.viewport-topbar {
  position: absolute;
  top: 18px;
  left: 22px;
  right: 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.viewport-topbar p {
  margin-top: 6px;
  color: #9fb3b0;
  font-size: 13px;
}

.status-pill,
.stable-label {
  flex: 0 0 auto;
  border: 1px solid #3a4749;
  border-radius: 4px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.status-pill.is-live,
.status-pill.is-manual,
.stable-label.is-stable {
  color: #aef2c4;
  border-color: #2d6e45;
  background: #123322;
}

.status-pill.is-waiting {
  color: #ffd38c;
  border-color: #7a5a23;
  background: #372711;
}

.status-pill.is-error,
.stable-label.is-unstable {
  color: #ffb7ad;
  border-color: #8b3d36;
  background: #3d1816;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  height: 100%;
  padding: 14px;
  overflow: auto;
  border-left: 1px solid #2a3034;
  background: #1d2225;
}

.panel {
  border: 1px solid #30383c;
  border-radius: 6px;
  background: #22282c;
}

.endpoint-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 74px;
  padding: 14px;
}

.section-kicker {
  display: block;
  margin-bottom: 4px;
  color: #9fb3b0;
  font-size: 12px;
}

#endpointValue {
  display: block;
  width: 268px;
  overflow: hidden;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid #30383c;
  color: #b7c6c3;
}

.panel-header h2 {
  color: #eef4f2;
  font-size: 14px;
  line-height: 1;
}

.panel-header span {
  font-size: 12px;
}

button {
  height: 28px;
  border: 1px solid #465358;
  border-radius: 4px;
  padding: 0 10px;
  background: #2c3438;
  color: #e6eeee;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

button:hover {
  background: #374146;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.head-control-row {
  justify-content: flex-end;
  min-width: 250px;
}

.head-neutral-status {
  width: 42px;
  color: #9fb3b0;
  text-align: right;
  font-size: 11px;
}

.timestamp-value {
  width: 74px;
  color: #b7c6c3;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.servo-grid {
  display: grid;
  grid-template-columns: 1fr;
}

.servo-row {
  display: grid;
  grid-template-columns: 58px 1fr 70px 72px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border-bottom: 1px solid #30383c;
  font-size: 12px;
}

.servo-row:last-child {
  border-bottom: 0;
}

.servo-name {
  color: #dfe8e6;
  font-weight: 700;
}

.servo-bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: #151a1d;
}

.servo-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #54c6b0, #f2c86b);
}

.servo-value {
  color: #b7c6c3;
  text-align: right;
}

.manual-servo-grid {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.manual-servo-row {
  display: grid;
  grid-template-columns: 42px minmax(120px, 1fr) minmax(66px, 82px);
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #b7c6c3;
  font-size: 12px;
}

.manual-servo-name {
  color: #dfe8e6;
  font-weight: 700;
}

.manual-servo-row input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: #54c6b0;
}

.manual-servo-row input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid #3b464a;
  border-radius: 4px;
  padding: 0 7px;
  background: #151a1d;
  color: #eef4f2;
  font: inherit;
  font-size: 12px;
}

.target-control-grid {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.target-row {
  display: grid;
  grid-template-columns: 26px minmax(120px, 1fr) minmax(70px, 86px);
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #b7c6c3;
  font-size: 12px;
}

.target-row span {
  color: #dfe8e6;
  font-weight: 700;
}

.target-row input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: #f2c86b;
}

.target-row input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid #3b464a;
  border-radius: 4px;
  padding: 0 7px;
  background: #151a1d;
  color: #eef4f2;
  font: inherit;
  font-size: 12px;
}

.target-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid #30383c;
  padding: 12px;
}

.target-preset-grid button {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
}

.motion-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  border-top: 1px solid #30383c;
  padding: 0 12px;
  color: #9fb3b0;
  font-size: 12px;
}

.serial-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  border-top: 1px solid #30383c;
  padding: 0 12px;
  color: #9fb3b0;
  font-size: 12px;
}

.serial-status-row span:last-child {
  min-width: 0;
  overflow: hidden;
  color: #b7c6c3;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#motionStageValue {
  flex: 0 0 auto;
  color: #f2c86b;
  font-weight: 700;
}

#motionTargetValue {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button:disabled,
.manual-servo-row input:disabled,
.target-row input:disabled,
.target-preset-grid button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.servo-row.is-disabled,
.manual-servo-row.is-disabled {
  opacity: 0.4;
}

.coord-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.coord-table th,
.coord-table td {
  height: 34px;
  padding: 0 10px;
  border-bottom: 1px solid #30383c;
  text-align: right;
}

.coord-table th:first-child,
.coord-table td:first-child {
  text-align: left;
}

.coord-table th {
  color: #9fb3b0;
  font-weight: 600;
}

.coord-table tr:last-child td {
  border-bottom: 0;
}

.dh-table-wrap {
  overflow-x: auto;
}

.dh-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 11px;
}

.dh-table th,
.dh-table td {
  height: 34px;
  padding: 4px;
  border-bottom: 1px solid #30383c;
  text-align: center;
}

.dh-table th {
  color: #9fb3b0;
  font-weight: 600;
}

.dh-table input,
.dh-table select {
  width: 100%;
  height: 26px;
  border: 1px solid #3b464a;
  border-radius: 4px;
  padding: 0 5px;
  background: #151a1d;
  color: #eef4f2;
  font: inherit;
  font-size: 11px;
}

#dhOutput {
  max-height: 116px;
  margin: 0;
  overflow: auto;
  border-top: 1px solid #30383c;
  padding: 10px 12px;
  color: #b7c6c3;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.log-panel {
  min-height: 170px;
  flex: 1 0 170px;
}

#eventLog {
  height: calc(100% - 42px);
  min-height: 126px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  color: #b7c6c3;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  color: #b7c6c3;
  font-size: 12px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: #54c6b0;
}

.calibration-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  color: #b7c6c3;
  font-size: 12px;
}

.field-row select,
.calibration-grid input {
  width: 100%;
  min-width: 0;
  height: 30px;
  border: 1px solid #3b464a;
  border-radius: 4px;
  background: #151a1d;
  color: #eef4f2;
  font: inherit;
  font-size: 12px;
}

.field-row select {
  padding: 0 8px;
}

.calibration-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.calibration-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #9fb3b0;
  font-size: 11px;
}

.calibration-grid input {
  padding: 0 7px;
}

#calibrationOutput {
  max-height: 150px;
  margin: 0;
  overflow: auto;
  border: 1px solid #30383c;
  border-radius: 4px;
  padding: 10px;
  background: #171c1f;
  color: #b7c6c3;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 58vh) auto;
    height: auto;
    min-height: 100vh;
  }

  .inspector {
    height: auto;
    border-left: 0;
    border-top: 1px solid #2a3034;
  }

  .manual-servo-row {
    grid-template-columns: 36px minmax(0, 1fr) 68px;
  }
}
