:root {
  --background: #f3f4f6;
  --surface: #ffffff;
  --tile: #e8eaed;
  --ink: #15171a;
  --muted: #5b616a;
  --accent: #0b7a5c;
  --accent-ink: #ffffff;
  --focus: #2f6fdb;
  --radius: 10px;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #101113;
    --surface: #18191c;
    --tile: #2a2c30;
    --ink: #ececee;
    --muted: #a3a8b0;
    --accent: #3fc79c;
    --accent-ink: #06261c;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.4;
}

a { color: inherit; text-decoration: none; }

svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  height: 100vh;
  height: 100dvh;
}

.robots, .joints {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
  gap: 12px;
  background: var(--surface);
  user-select: none;
}

.brand-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.brand { font-weight: 650; font-size: 15px; }
.dataset-link { color: var(--muted); font-size: 13px; }
.dataset-link:hover { color: var(--ink); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--background);
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font: inherit;
}

.robot-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0 -6px;
  padding: 0;
}
.robot-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px;
  border-radius: 8px;
}
.robot-list a:hover { background: var(--background); }
.robot-list a.active { background: var(--tile); font-weight: 600; }
.robot-list img {
  width: 36px;
  height: 36px;
  flex: none;
  object-fit: cover;
  border-radius: 6px;
  background: var(--tile);
}
.robot-list span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stage { position: relative; min-width: 0; min-height: 0; }
#view { display: block; width: 100%; height: 100%; touch-action: none; }
.status {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--muted);
}

.robot-name { margin: 0; font-size: 18px; font-weight: 650; line-height: 1.25; }
.robot-facts { margin: -8px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.joint-actions { display: flex; gap: 8px; }
.joint-actions button, .joint-actions select {
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: var(--background);
  color: var(--ink);
  font: inherit;
}
.joint-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.joint-actions button:hover { background: var(--tile); }
.joint-actions select { flex: 1; min-width: 0; }

.joint-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}
.joint {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: baseline;
}
.joint-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.joint-value { color: var(--muted); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.joint input {
  grid-column: 1 / -1;
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.links { display: flex; flex-direction: column; gap: 8px; }
.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.licence { margin: 0; color: var(--muted); font-size: 12px; user-select: text; }

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 44dvh auto auto;
    height: auto;
  }
  .stage { order: 0; height: 44dvh; }
  .joints { order: 1; }
  .joint-list { max-height: 50dvh; }
  .robots { order: 2; }
  .robot-list { max-height: 40dvh; }
}
