:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --text: #1c2430;
  --muted: #5c6776;
  --line: #d9dee5;
  --accent: #1b63b8;
  --on-accent: #ffffff;
  --accent-2: #eb6a1f;
  --error: #c62f2f;
  --warning: #9a5b00;
  --info: #2a6fb3;
  --sel: #fff1e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --panel: #181c22;
  --panel-2: #1f242b;
  --text: #e5e9ef;
  --muted: #98a2b0;
  --line: #2c323b;
  --accent: #5aa2f0;
  --on-accent: #0f1216;
  --accent-2: #ff8a3d;
  --error: #ff6b6b;
  --warning: #f0b04a;
  --info: #6fb0f2;
  --sel: #3a2a1b;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  font:
    14px/1.45 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}

button,
.button-like,
select,
input[type="text"] {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
}

button,
.button-like {
  cursor: pointer;
}

button:hover,
.button-like:hover {
  border-color: var(--accent);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible,
canvas:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* The selected tree entry keeps its own outline; focus adds a thicker one. */
.tree button.selected:focus-visible {
  outline: 2px solid var(--accent);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.top h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top nav {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 360px;
  gap: 10px;
  padding: 10px;
}

.side {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel > summary {
  cursor: pointer;
  padding: 9px 12px;
  font-weight: 600;
  list-style: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

.panel > summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s;
}

.panel[open] > summary::before {
  transform: rotate(90deg);
}

.panel > summary::-webkit-details-marker {
  display: none;
}

.panel-body {
  padding: 0 12px 12px;
}

.count {
  color: var(--muted);
  font-weight: 400;
}

.drop {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
  padding: 14px 10px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
}

.drop:hover {
  border-color: var(--accent);
}

.drop span {
  color: var(--muted);
  font-size: 12.5px;
}

.drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* File inputs shown as a button-like label: kept in the tab order (a hidden
   input cannot be reached with the keyboard); the label shows the focus. */
.file-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.file-sr:focus-visible + .button-like {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.drop:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
  position: relative;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 8px 0;
}

.field > span {
  color: var(--muted);
  font-size: 12.5px;
}

.field select,
.field input {
  width: 100%;
}

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

.attribution {
  font-style: italic;
}

#args h3 {
  font-size: 13px;
  margin: 12px 0 2px;
}

.field.arg {
  flex-direction: row;
  align-items: center;
  margin: 4px 0;
}

.field.arg > span {
  flex: 0 0 45%;
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  margin: 10px 0 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.summary {
  margin: 0;
  font-weight: 600;
  font-size: 13px;
}

.muted {
  color: var(--muted);
}

/* ------------------------------------------------------------ tree */
.tree ul {
  list-style: none;
  margin: 0;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.tree > ul.tree-root {
  padding-left: 0;
  border-left: 0;
}

.tree li {
  margin: 1px 0;
}

.tree button {
  border: 0;
  background: none;
  padding: 2px 6px;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: left;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree button:hover {
  background: var(--panel-2);
}

.tree button.selected {
  background: var(--sel);
  outline: 1px solid var(--accent-2);
}

.t-link::before {
  content: "■ ";
  color: var(--accent);
}

.t-joint {
  color: var(--muted);
}

.t-joint::before {
  content: "◆ ";
  color: var(--accent-2);
}

.t-joint.fixed::before {
  color: var(--muted);
}

.jt {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
}

/* ------------------------------------------------------------ viewport */
.viewport {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
}

#view {
  position: absolute;
  inset: 0;
}

#view canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toolbar > * {
  pointer-events: auto;
}

.toolbar button,
.toggle {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 12.5px;
}

.toggle {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  cursor: pointer;
}

.seg {
  display: inline-flex;
}

.seg button {
  border-radius: 0;
  margin-left: -1px;
}

.seg button:first-child {
  border-radius: 7px 0 0 7px;
}

.seg button:last-child {
  border-radius: 0 7px 7px 0;
}

.seg button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.hint {
  position: absolute;
  bottom: 6px;
  left: 10px;
  right: 10px;
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  pointer-events: none;
}

.dropping {
  display: none;
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

body.is-dragging .dropping {
  display: flex;
}

/* ------------------------------------------------------------ details & joints */
#details h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-family: var(--mono);
  word-break: break-all;
}

#details dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 10px;
  margin: 0;
  font-size: 12.5px;
}

#details dt {
  color: var(--muted);
}

#details dd {
  margin: 0;
  font-family: var(--mono);
  word-break: break-word;
}

.j-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 8px;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.j-name {
  border: 0;
  background: none;
  padding: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.j-row input[type="range"] {
  grid-column: 1 / 2;
  width: 100%;
  accent-color: var(--accent-2);
}

.j-row output {
  grid-column: 2;
  grid-row: 1 / 3;
  font-family: var(--mono);
  font-size: 12px;
  min-width: 82px;
  text-align: right;
}

.j-range {
  grid-column: 1 / 3;
  font-size: 11px;
  color: var(--muted);
}

#joints > button {
  margin-top: 8px;
}

/* ------------------------------------------------------------ findings */
.findings {
  list-style: none;
  margin: 0;
}

.finding {
  border-left: 3px solid var(--info);
  padding: 4px 0 6px 9px;
  margin: 6px 0;
}

.finding.error {
  border-color: var(--error);
}

.finding.warning {
  border-color: var(--warning);
}

.finding p {
  margin: 3px 0 0;
  font-size: 12.5px;
  word-break: break-word;
}

.finding .why {
  color: var(--muted);
  font-size: 12px;
}

.f-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  border: 0;
  background: none;
  padding: 0;
  width: 100%;
  text-align: left;
  flex-wrap: wrap;
}

.sev {
  text-transform: uppercase;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.sev.error {
  color: var(--error);
}

.sev.warning {
  color: var(--warning);
}

.sev.info {
  color: var(--info);
}

.loc {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
}

#urdf {
  max-height: 340px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--panel-2);
  padding: 8px;
  border-radius: 7px;
  margin: 8px 0 0;
}

.foot {
  padding: 6px 18px 10px;
  color: var(--muted);
  font-size: 12px;
}

/* ------------------------------------------------------------ narrow screens */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }
  .side.right {
    grid-column: 1 / 3;
  }
}

@media (max-width: 760px) {
  body {
    display: block;
    height: auto;
  }
  .top {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px;
  }
  .top nav {
    justify-content: flex-start;
  }
  .layout {
    display: flex;
    flex-direction: column;
    padding: 8px;
  }
  .viewport {
    order: -1;
    height: 58vh;
    min-height: 320px;
  }
  .side {
    overflow: visible;
  }
  .hint {
    display: none;
  }
}

/* ------------------------------------------------------------ builder */
.toolbar.edit-bar {
  top: 48px;
}

.edit-bar button:disabled {
  opacity: 0.45;
  cursor: default;
}

.edit-status {
  font-size: 12px;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border-radius: 6px;
  padding: 2px 6px;
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-status:empty {
  display: none;
}

fieldset.params {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 8px 0;
  padding: 4px 8px 6px;
}

fieldset.params legend {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}

.param-switch {
  margin: 6px 0 2px;
  border: none;
  background: none;
  backdrop-filter: none;
  padding: 0;
  font-size: 13px;
}

.prop {
  display: grid;
  grid-template-columns: 28% minmax(0, 1fr) 2.8em;
  gap: 6px;
  align-items: center;
  margin: 3px 0;
}

.prop-label {
  color: var(--muted);
  font-size: 12.5px;
}

.prop-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.prop-inputs input[type="text"],
.prop-inputs select {
  flex: 1 1 calc(33.3% - 4px);
  min-width: 0;
  width: 0;
  padding: 3px 6px;
  font-family: var(--mono);
  font-size: 12.5px;
}

.prop-inputs select {
  font-family: inherit;
}

.prop .unit {
  color: var(--muted);
  font-size: 11.5px;
}

input.invalid {
  border-color: var(--error);
  outline: 1px solid var(--error);
}

#details h3 {
  font-size: 13px;
  margin: 14px 0 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

#details h3:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

#details h4 {
  font-size: 12.5px;
  margin: 10px 0 2px;
  color: var(--muted);
  font-weight: 600;
}

.row.actions {
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

.row.actions button,
.row.actions select {
  font-size: 12.5px;
  padding: 3px 8px;
}

.row.actions input[type="color"] {
  width: 2.4em;
  height: 1.9em;
  padding: 1px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

button.danger:hover {
  border-color: var(--error);
  color: var(--error);
}

#p-build .row,
#p-export .row {
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .toolbar.edit-bar {
    top: auto;
    bottom: 8px;
  }
}

/* ------------------------------------------------------------ simulation */
.badge-sim {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: #6d3fdc;
  border-radius: 4px;
  padding: 1px 5px;
}

details.sub {
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 6px;
}

details.sub > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

.field.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.field.inline > span {
  margin: 0;
}

.seg.tools {
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.seg.tools button {
  font-size: 12px;
  padding: 3px 7px;
}

#world-canvas {
  display: block;
  width: 100%;
  height: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  touch-action: none;
  margin-bottom: 6px;
}

.sim-fields {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  font-size: 12.5px;
}

.sim-fields input[type="text"] {
  width: 7ch;
  padding: 2px 6px;
}

.sim-fields .group {
  grid-column: 1 / 3;
  font-weight: 600;
  color: var(--muted);
  margin-top: 6px;
}

.sim-hud {
  position: absolute;
  right: 10px;
  bottom: 30px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.sim-hud table {
  border-collapse: collapse;
  margin-top: 3px;
}

.sim-hud td,
.sim-hud th {
  padding: 0 6px 0 0;
  text-align: right;
  font-weight: normal;
}

.sim-hud th {
  color: var(--muted);
}

.sim-hud td:first-child {
  text-align: left;
}

.sim-hud .sw {
  display: inline-block;
  width: 10px;
  height: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

.hud-perf {
  color: var(--muted);
  margin-top: 2px;
}

fieldset.layers {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 8px 0;
  padding: 4px 8px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  font-size: 12.5px;
}

fieldset.layers legend {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
}

.sticks {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 74px;
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.stick {
  pointer-events: auto;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  position: relative;
  touch-action: none;
}

.stick span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
}

#stick-turn {
  height: 46px;
  margin-top: 46px;
  border-radius: 23px;
}

.plots canvas {
  display: block;
  width: 100%;
  height: 118px;
  margin-bottom: 6px;
}

/* On-screen sticks on touch screens; keyboard and gamepad elsewhere. */
@media (pointer: coarse) {
  .sticks {
    display: flex;
  }
}

@media (max-width: 760px) {
  .sim-hud {
    bottom: 8px;
  }
  .sticks {
    bottom: 110px;
  }
}

/* ------------------------------------------------------------ ROS 2: live robot and replays */
.badge-sim.live {
  background: #c62f2f;
}

.badge-sim.replay {
  background: #1f7a4d;
}

.drive-banner {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  background: #c62f2f;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 6px 14px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 30%);
  z-index: 5;
  pointer-events: none;
  text-align: center;
  font-size: 13px;
}

.drive-banner small {
  display: block;
  font-weight: 500;
  letter-spacing: 0;
}

.drive-banner.armed {
  background: #b26a00;
}

.ros-topics {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

.ros-topics td,
.ros-topics th {
  padding: 1px 4px;
  text-align: right;
}

.ros-topics td:first-child,
.ros-topics th:first-child {
  text-align: left;
}

.ros-topics .stale {
  color: var(--muted);
}

.ros-topics .bad {
  color: var(--error);
}

.ros-drive {
  border: 1px solid var(--error);
  border-radius: 6px;
  padding: 6px 8px;
  margin-top: 8px;
}

.ros-drive label.confirm {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 12.5px;
}

.sub-h {
  font-size: 13px;
  margin: 10px 0 4px;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
}

/* ------------------------------------------------------------ first run: start here, guided example */
.welcome {
  position: absolute;
  inset: 52px 12px 12px;
  z-index: 5;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgb(0 0 0 / 18%);
  padding: 16px 18px;
}

.welcome.touring {
  inset: auto 12px 12px;
  max-height: 45%;
}

.welcome h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.wcard {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
}

.wcard h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.wcard p {
  margin: 0;
  color: var(--text);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

#tour-text {
  max-width: 70ch;
}
