:root {
  --bg: #1c2127;
  --panel: #232930;
  --panel-2: #2b323b;
  --surface: #1a1f25;
  --border: #3b4450;
  --border-soft: rgba(255, 255, 255, 0.11);
  --text: #edf1f5;
  --text-soft: #cfd7e0;
  --muted: #98a4b2;
  --accent: #f26c1d;
  --accent-hover: #ff7e33;
  --accent-cool: #52b6e6;
  --ok: #34d399;
  --warn: #f59e0b;
  --danger: #ef4444;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 1fr 356px;
  width: 100vw;
  height: 100vh;
}
.app-shell.sidebar-collapsed {
  grid-template-columns: 1fr;
}
.app-shell.sidebar-collapsed .sidebar {
  display: none;
}

sub, sup {
  font-size: 0.74em;
  line-height: 0;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(90deg, #21262d 0%, #293038 100%);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand-pill {
  background: rgba(242, 108, 29, 0.14);
  color: #ff985a;
  border: 1px solid rgba(242, 108, 29, 0.36);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
}

.demo-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.demo-tabs::-webkit-scrollbar { display: none; }

.demo-tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.demo-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.demo-tab.active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 2px 10px rgba(242, 108, 29, 0.28);
}

.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-link {
  color: var(--text-soft);
  text-decoration: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-link:hover {
  border-color: var(--accent-cool);
  color: var(--text);
}
.nav-link.highlight {
  border-color: rgba(82, 182, 230, 0.45);
  color: #8ad2f4;
  background: rgba(82, 182, 230, 0.10);
}
.nav-link.highlight:hover {
  border-color: var(--accent-cool);
  background: rgba(82, 182, 230, 0.18);
  color: #ffffff;
}

.viewport-wrap {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #6e7f8c 0%, #4b545d 52%, #3b424a 100%);
}

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

.hud-top-left {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  pointer-events: none;
}

.hud-chip {
  background: rgba(28, 33, 39, 0.72);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 11px;
  display: flex;
  gap: 6px;
  align-items: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.hud-chip .k { color: var(--muted); }
.hud-chip .v { color: var(--text); font-weight: 600; }
.hud-chip .v.ok { color: var(--ok); }
.hud-chip .v.warn { color: var(--warn); }

.hud-bottom-left {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.teleop-hud {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 248px;
  background: rgba(25, 30, 36, 0.84);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 9px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  user-select: none;
}
.teleop-hud.hidden { display: none; }
.teleop-hud-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  font-family: var(--mono);
  font-size: 10px;
}
.teleop-badge {
  background: rgba(242, 108, 29, 0.22);
  color: #ffb07d;
  border: 1px solid rgba(242, 108, 29, 0.55);
  border-radius: 5px;
  padding: 2px 6px;
  font-weight: 700;
}
.teleop-pill {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
  border-radius: 5px;
  padding: 2px 6px;
  font-weight: 600;
}
.teleop-pill.warn {
  background: rgba(245, 158, 11, 0.22);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.55);
}
.teleop-pill.ok {
  background: rgba(52, 211, 153, 0.20);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.50);
}
.teleop-pill.hidden { display: none; }

.teleop-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin-bottom: 8px;
}
.teleop-axis {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}
.teleop-axis span { width: 16px; text-align: right; }
.tbar {
  position: relative;
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 3px;
  overflow: hidden;
}
.tbar::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.25);
}
.tbar i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
}

.teleop-key-grid {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.key-cluster {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.key-row { display: flex; gap: 3px; }
.keycap {
  width: 28px;
  height: 24px;
  padding: 0;
  background: rgba(52, 61, 72, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
  transition: background 0.08s ease, transform 0.08s ease;
}
.keycap:hover { border-color: rgba(255, 255, 255, 0.35); color: #fff; }
.keycap.active {
  background: var(--accent);
  border-color: #ff9c63;
  color: #fff;
  transform: translateY(1px);
}
.cluster-lbl {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.teleop-foot {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  line-height: 1.35;
}
.teleop-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}
.teleop-hint code {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 4px;
  border-radius: 4px;
}
.control-row.dimmed { opacity: 0.45; }

.cam-btn {
  background: rgba(28, 33, 39, 0.74);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-soft);
  color: var(--text-soft);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16);
}
.cam-btn:hover {
  color: #ffffff;
  border-color: rgba(242, 108, 29, 0.65);
  background: rgba(38, 45, 54, 0.88);
}
.cam-btn.active {
  color: #ffffff;
  background: rgba(242, 108, 29, 0.90);
  border-color: var(--accent);
}

.loading-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(30, 35, 42, 0.88);
  backdrop-filter: blur(8px);
  z-index: 10;
  transition: opacity 0.25s ease;
}
.loading-banner.hidden {
  opacity: 0;
  pointer-events: none;
}
.load-card {
  width: min(360px, 86vw);
  background: rgba(35, 41, 48, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.load-progress-track {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  overflow: hidden;
}
.load-progress-fill {
  height: 100%;
  width: 2%;
  background: linear-gradient(90deg, var(--accent) 0%, #ff985a 100%);
  border-radius: 999px;
  transition: width 0.12s linear;
}
.load-progress-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(242, 108, 29, 0.22);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sidebar {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #46515e transparent;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar::-webkit-scrollbar { width: 7px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #46515e; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #596676; }

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

.card h3 {
  margin: 0 0 8px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}

.desc-text {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  min-width: 72px;
  background: #343d48;
  color: var(--text);
  border: 1px solid #485362;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}
.btn:hover { border-color: var(--accent-cool); background: #3d4855; }
.btn.primary { background: var(--accent); color: #ffffff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.impulse { background: rgba(242, 108, 29, 0.16); color: #ffb27d; border-color: rgba(242, 108, 29, 0.45); }
.btn.impulse:hover { background: rgba(242, 108, 29, 0.28); color: #ffffff; }

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.control-row:last-child { margin-bottom: 0; }
.control-row label { color: var(--text-soft); font-size: 12px; }
.control-row .val { font-family: var(--mono); font-size: 11px; color: #ff985a; min-width: 48px; text-align: right; }

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}
select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.metric-box {
  background: rgba(26, 31, 37, 0.72);
  border: 1px solid rgba(72, 83, 98, 0.65);
  border-radius: 7px;
  padding: 7px 9px;
}
.metric-box .mlabel { font-size: 10px; color: var(--muted); letter-spacing: 0.2px; }
.metric-box .mval { font-family: var(--mono); font-size: 14px; font-weight: 700; margin-top: 2px; color: var(--text); }

canvas.chart {
  width: 100%;
  height: 128px;
  display: block;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid rgba(72, 83, 98, 0.75);
}

.chart-legend {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 54vh 1fr;
  }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
