/* =====================================================================
 *  ROS-симулятор (/ros2/sim/) — тёмная гамма урокробототехники.рф.
 *
 *  Главное поле — карта мира на весь экран; консоль, задания и слои —
 *  панели поверх неё, которые прикрепляются к любой стороне или висят
 *  отдельным окном. Положение и размер панелей считает ros-sim.js и
 *  ставит инлайном (left/top/width/height), здесь только их вид.
 *  Главная панель сверху (режим, Старт/Стоп, файл, «Панели ▾») — общая с
 *  редактором схем, её стили в ../app-bar.css.
 *
 *  Синтаксис нарочно без новинок (container queries, aspect-ratio): у
 *  школьных машин встречаются очень немолодые браузеры — по той же
 *  причине в проекте закреплена сборка @wokwi/elements 1.7.0. Узкую
 *  панель помечает скрипт атрибутом data-w, а не @container.
 * ===================================================================== */

:root {
  --bg: #0c090c;
  --surface: #17131a;
  --surface-2: #1d1822;
  --head: #1b161e;
  --ink: #f7f0ea;
  --ink-2: #c6bab5;
  --ink-3: #9b8f8c;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.17);
  --brand: #ff8a5c;
  --brand-2: #ffa77f;
  --brand-ink: #26100a;
  --ok: #6fdcab;
  --ok-bg: #0f1d18;
  --warn: #f2b571;
  --danger: #ff9aae;
  --danger-bg: #251419;
  --sky: #93bdff;
  --sky-bg: #141b28;
  --violet: #b99cff;
  --violet-bg: #1a1528;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Montserrat, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --shadow-float: 0 34px 70px -24px rgba(0, 0, 0, 0.95), 0 4px 14px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--brand); }
a:hover { color: var(--brand-2); }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(240, 102, 58, 0.55);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app { height: 100vh; min-height: 560px; display: flex; flex-direction: column; }

/* ── Верхняя строка ─────────────────────────────────────────── */
/* Главная панель — ../app-bar.css (общая с редактором схем). Здесь —
   только значки-кнопки шапок панелей. */
.ib {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 0;
  color: var(--ink-3);
  background: transparent;
  cursor: pointer;
}
.ib:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
.ib:disabled { opacity: 0.35; cursor: default; background: transparent; }
.ib[aria-pressed="true"] { color: var(--brand); background: rgba(255, 138, 92, 0.14); }

/* ── Рабочая область и карта ────────────────────────────────── */
.ws { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.ws.is-resizing, .ws.is-resizing * { user-select: none; -webkit-user-select: none; }
.ws.is-resizing .vp { transition: none; }
.ws[data-rcur="ew"], .ws[data-rcur="ew"] * { cursor: ew-resize !important; }
.ws[data-rcur="ns"], .ws[data-rcur="ns"] * { cursor: ns-resize !important; }
.ws[data-rcur="nwse"], .ws[data-rcur="nwse"] * { cursor: nwse-resize !important; }
.ws[data-rcur="grab"], .ws[data-rcur="grab"] * { cursor: grabbing !important; }

.vp {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #0f0c10;
  background-image: radial-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1.3px);
  background-size: 20px 20px;
  transition: top 0.25s, right 0.25s, bottom 0.25s, left 0.25s;
  overflow: hidden;
}
.stage { position: absolute; top: 60px; right: 12px; bottom: 12px; left: 12px; overflow: hidden; }
.world-art { position: absolute; display: block; pointer-events: none; }
.stage.no-world .world-art { display: none; }
#field { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#field.is-panning { cursor: grabbing; }

.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: max-content;
  padding: 5px;
  border-radius: 14px;
  background: rgba(23, 19, 26, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
/* Карта и задача — первым пунктом полосы над картой: миниатюра, название
   карты и задача; по щелчку — меню выбора (.env-menu, живёт в <body>). */
.hud-sel { display: inline-flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border: 0; border-radius: 10px; font: inherit; color: var(--ink-3); background: #221c27; cursor: pointer; pointer-events: auto; text-align: left; }
.hud-sel:hover, .hud-sel[aria-expanded="true"] { color: var(--ink); background: #2a2230; }
.hud-sel-img { display: block; width: 34px; height: 24px; border-radius: 6px; object-fit: cover; background: #151214; }
.hud-sel-t { display: flex; flex-direction: column; gap: 1px; line-height: 1.15; }
.hud-sel-t b { font-size: 12.5px; color: var(--ink); white-space: nowrap; }
.hud-sel-t small { font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.env-menu { position: fixed; z-index: 5300; width: 300px; max-width: calc(100vw - 16px); overflow: auto; padding: 6px; border-radius: 14px; background: #1b161e; border: 1px solid rgba(255, 255, 255, 0.12); box-shadow: var(--shadow-float); font: 500 13px/1.3 var(--sans); }
.env-cap { padding: 6px 8px 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.env-map { padding: 6px; border-radius: 10px; }
.env-map + .env-map { margin-top: 4px; }
.env-map.is-cur { background: rgba(255, 255, 255, 0.03); }
.env-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.env-head img { display: block; width: 64px; height: 42px; border-radius: 8px; object-fit: cover; background: #151214; border: 1px solid rgba(255, 255, 255, 0.08); }
.env-head b { display: block; font-size: 13.5px; color: var(--ink); }
.env-head small { font-size: 11.5px; color: var(--ink-3); }
.env-task { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 10px 0 28px; border-radius: 8px; color: var(--ink-2); text-decoration: none; position: relative; }
.env-task:hover { background: rgba(255, 255, 255, 0.07); color: var(--ink); }
.env-task[aria-current="true"] { color: var(--brand); font-weight: 700; }
.env-task[aria-current="true"]::before { content: ""; position: absolute; left: 12px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--brand); }
.env-all { display: block; margin-top: 6px; padding: 9px 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); color: var(--sky); text-decoration: none; }
.env-all:hover { color: var(--brand); }
/* Пока карта грузится, раскладки панелей ещё нет — не показываем кашу. */
.booting .ws { visibility: hidden; }
.map-error { position: absolute; top: 40%; left: 0; right: 0; margin: 0 auto; max-width: 460px; padding: 14px 16px; border-radius: 12px; text-align: center; color: var(--ink); background: var(--danger-bg); visibility: visible; }
.hud-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--surface-2);
}
.hud-state i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.hud-state[data-tone="ok"] { color: var(--ok); background: var(--ok-bg); }
.hud-state[data-tone="ok"] i { background: var(--ok); box-shadow: 0 0 0 3px rgba(111, 220, 171, 0.2); }
.hud-state[data-tone="warn"] { color: var(--warn); background: #241b12; }
.hud-state[data-tone="warn"] i { background: var(--warn); }
.hud-state[data-tone="bad"] { color: var(--danger); background: var(--danger-bg); }
.hud-state[data-tone="bad"] i { background: var(--danger); }
.hud-m { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.hud-m b { color: var(--ink); font-variant-numeric: tabular-nums; min-width: 34px; }
.hud-bar { width: 32px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.hud-bar span { display: block; height: 5px; width: 0; border-radius: 3px; background: var(--warn); transition: width 0.3s; }
.hud-bar.batt span { background: var(--ok); }
.hud-bar.batt.low span { background: var(--brand); }
.hud-bar.batt.crit span { background: #ff5a5a; }

.status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 260px);
  padding: 6px 10px;
  border-radius: 10px;
  font: 12px/1.45 var(--mono);
  color: var(--ink-2);
  background: rgba(23, 19, 26, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.status:empty { display: none; }
.status.is-flash { color: var(--brand-2); border-color: rgba(255, 138, 92, 0.45); }

.zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  padding: 3px;
  border-radius: 12px;
  background: rgba(23, 19, 26, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.zoom .ib { width: 34px; height: 34px; font: 600 18px/1 var(--sans); color: var(--ink-2); }
.zoom-val { min-width: 48px; text-align: center; font: 600 12.5px/1 var(--mono); color: var(--ink-2); }

.overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 26px 24px;
  border-radius: 20px;
  text-align: center;
  background: rgba(23, 19, 26, 0.96);
  border: 1px solid rgba(255, 138, 92, 0.35);
  box-shadow: var(--shadow-float);
}
.overlay p { margin: 0; font-size: 18px; font-weight: 700; }
.overlay-sub { font-size: 14px !important; font-weight: 500 !important; color: var(--ink-3); }
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  max-width: 100%;
  padding: 10px 20px;
  border-radius: 999px;
  border: 0;
  font-weight: 700;
  color: var(--brand-ink);
  background: linear-gradient(135deg, #ffa77f, #f0663a);
  box-shadow: 0 16px 32px -14px rgba(240, 102, 58, 0.5);
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary.code { font-family: var(--mono); font-size: 13.5px; font-weight: 600; overflow-wrap: anywhere; }

/* ── Панель «Пульт»: кнопки teleop и показания скорости ── */
.tele-body { position: relative; padding: 14px; }
.tele-main { display: flex; align-items: center; gap: 16px; transition: opacity 0.15s; }
.pnl[data-w="xs"] .tele-main { flex-direction: column; align-items: stretch; }
.tele-pad {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
  justify-content: center;
}
.tk {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, #251f2b, #1a1520);
  color: var(--ink-2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 6px 14px -8px rgba(0, 0, 0, 0.85);
  cursor: pointer;
  touch-action: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}
.tk:hover { color: var(--ink); border-color: rgba(255, 138, 92, 0.45); }
.tk kbd { position: absolute; right: 6px; bottom: 4px; font: 700 10px/1 var(--mono); color: var(--ink-3); }
/* Зажатое направление — с кнопки или с клавиатуры — видно на той же кнопке:
   пока горит, робот едет. */
.tk:active, .tk.is-on { transform: scale(0.95); color: #fff; border-color: var(--brand); background: rgba(255, 138, 92, 0.3); box-shadow: 0 0 18px -4px rgba(255, 138, 92, 0.55); }
.tk.stop { color: #ff9aae; }
.tk.stop:active { color: #fff; border-color: #ff7a90; background: rgba(255, 122, 144, 0.3); }
.tk.up { grid-column: 2; grid-row: 1; }
.tk.left { grid-column: 1; grid-row: 2; }
.tk.stop { grid-column: 2; grid-row: 2; }
.tk.right { grid-column: 3; grid-row: 2; }
.tk.down { grid-column: 2; grid-row: 3; }
.tele-meters { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.tele-ml { display: block; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.tele-mv { display: block; margin: 2px 0 7px; font: 600 15px/1.2 var(--mono); color: var(--ink); white-space: nowrap; }
/* Ноль посередине: влево — назад или поворот вправо, вправо — наоборот. */
.tele-bar { position: relative; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); }
.tele-bar::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; border-radius: 1px; background: rgba(255, 255, 255, 0.28); }
.tele-bar i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; border-radius: 4px; background: var(--brand); transition: left 0.12s, width 0.12s; }
.tele-bar.ang i { background: var(--sky); }
/* Подсказка по клавишам — сеткой 2 × 2 под пультом. */
.tele-keys {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: start;
  gap: 6px 18px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
}
.pnl[data-w="xs"] .tele-keys { grid-template-columns: auto; }
.tele-keys-cap { grid-column: 1 / -1; font-weight: 600; color: var(--ink-2); }
.tele-keys kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  margin-right: 2px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-width: 2px;
  background: var(--surface-2);
  font: 600 10.5px/1.5 var(--mono);
  color: var(--ink-2);
  text-align: center;
}
/* Мир не запущен или на паузе: пульт погашен, поверх — кнопка, которая это исправит. */
.pnl.is-off .tele-main, .pnl.is-off .tele-keys { opacity: 0.32; pointer-events: none; }
.tele-off {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px;
  background: rgba(23, 19, 26, 0.84);
  text-align: center;
}
.tele-off[hidden] { display: none; }
.tele-off p { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-2); }
.tele-off code { font-family: var(--mono); color: var(--brand-2); }
.tele-off .btn-primary { align-self: center; min-height: 40px; padding: 8px 20px; font-size: 13.5px; }

/* ── Панели ─────────────────────────────────────────────────── */
.pnl {
  position: absolute;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 20;
}
.pnl[data-dock="float"] { box-shadow: var(--shadow-float); }
.pnl.is-dragging { opacity: 0.9; pointer-events: none; outline: 2px solid var(--brand); }
.ph {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 46px;
  padding: 0 6px 0 4px;
  background: var(--head);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.ph button { cursor: pointer; }
.ph .grip { width: 30px; height: 34px; cursor: grab; }
.ph-title { margin: 0 8px 0 2px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.ph-count { font-size: 12.5px; font-weight: 700; color: var(--brand); white-space: nowrap; }
.ph-spacer { flex: 1 1 auto; }
.dockbtns { display: flex; }
.dockbtns .ib, .ph .ib-close { width: 28px; height: 30px; border-radius: 7px; }
.pnl[data-w="xs"] .dockbtns { display: none; }
.pnl-body { flex: 1 1 auto; min-height: 0; overflow: auto; }

.rh { position: absolute; display: none; z-index: 5; touch-action: none; outline: none; }
.rh::after { content: ""; position: absolute; background: var(--brand); opacity: 0; border-radius: 2px; transition: opacity 0.15s; }
.rh:hover::after, .rh:active::after, .rh:focus-visible::after { opacity: 1; }
.rh-n { top: 0; left: 14px; right: 14px; height: 9px; cursor: ns-resize; }
.rh-n::after { left: 0; right: 0; top: 0; height: 3px; }
.rh-s { bottom: 0; left: 14px; right: 14px; height: 9px; cursor: ns-resize; }
.rh-s::after { left: 0; right: 0; bottom: 0; height: 3px; }
.rh-e { right: 0; top: 14px; bottom: 14px; width: 9px; cursor: ew-resize; }
.rh-e::after { top: 0; bottom: 0; right: 0; width: 3px; }
.rh-w { left: 0; top: 14px; bottom: 14px; width: 9px; cursor: ew-resize; }
.rh-w::after { top: 0; bottom: 0; left: 0; width: 3px; }
.rh-se { right: 0; bottom: 0; width: 20px; height: 20px; cursor: nwse-resize; }
.rh-se::after { right: 4px; bottom: 4px; width: 9px; height: 9px; background: none; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); border-radius: 0 0 3px 0; opacity: 0.7; }
.rh-se:hover::after, .rh-se:active::after, .rh-se:focus-visible::after { border-color: var(--brand); opacity: 1; }
.pnl[data-dock="left"] .rh-e, .pnl[data-dock="right"] .rh-w, .pnl[data-dock="top"] .rh-s, .pnl[data-dock="bottom"] .rh-n { display: block; }
.pnl[data-dock="left"][data-last="false"] .rh-s, .pnl[data-dock="right"][data-last="false"] .rh-s,
.pnl[data-dock="top"][data-last="false"] .rh-e, .pnl[data-dock="bottom"][data-last="false"] .rh-e { display: block; }
.pnl[data-dock="float"] .rh-e, .pnl[data-dock="float"] .rh-s, .pnl[data-dock="float"] .rh-se { display: block; }
/* Узкий экран: панели одной стороны стоят друг под другом, граница между
   ними — горизонтальная. */
.pnl[data-stack="v"] .rh-e { display: none !important; }
.pnl[data-stack="v"][data-last="false"] .rh-s { display: block; }
.pnl.is-dragging .rh { display: none !important; }

/* Слои */
.layers-list { display: flex; flex-direction: column; padding: 4px; }
.lrow {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 8px;
  border-radius: 9px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 600 13px/1 var(--mono);
  text-align: left;
  cursor: pointer;
}
.lrow:hover { background: rgba(255, 255, 255, 0.05); }
.lrow.sans { font-family: var(--sans); }
.lrow-ck { flex: none; display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid rgba(255, 255, 255, 0.25); color: var(--brand-ink); }
.lrow[aria-pressed="true"] .lrow-ck { background: var(--brand); border-color: var(--brand); }
.lrow[aria-pressed="false"] .lrow-ck svg { display: none; }
.lrow[aria-pressed="false"] .lrow-name { color: var(--ink-3); }
.lrow-name { flex: 1; }
.lrow-sw { width: 10px; height: 10px; border-radius: 3px; }

/* Задания */
.tasks-wrap { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.progress { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.progress span { display: block; height: 5px; width: 0; border-radius: 3px; background: linear-gradient(90deg, #ffa77f, #f0663a); transition: width 0.3s; }
.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tasks details { border-radius: 12px; border: 1px solid transparent; }
.tasks details[open] { background: var(--violet-bg); border-color: rgba(185, 156, 255, 0.45); }
.tasks summary { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 7px 8px; border-radius: 10px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.tasks summary::-webkit-details-marker { display: none; }
.tasks summary:hover { background: rgba(255, 255, 255, 0.04); }
.tasks details[open] summary { color: var(--ink); font-weight: 700; }
.tasks details.done summary { color: var(--ink-3); }
.chk { flex: none; display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 7px; border: 2px solid rgba(255, 255, 255, 0.17); }
.tasks details[open] .chk { border-color: var(--violet); }
.tasks details.done .chk { border: 0; background: var(--ok-bg); color: var(--ok); }
.hintbox { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px 40px; }
.hintbox p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.hintbox code { display: block; padding: 9px 10px; border-radius: 10px; background: var(--bg); border: 1px solid rgba(255, 255, 255, 0.08); font: 12px/1.55 var(--mono); color: var(--violet); overflow-wrap: anywhere; }
.btn-soft {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font: 700 12.5px/1 var(--sans);
  color: var(--ink);
  background: #2a2230;
  border: 1px solid rgba(185, 156, 255, 0.4);
  cursor: pointer;
}
.btn-soft:hover { border-color: var(--violet); }

/* Консоль */
.ctabs { display: flex; gap: 4px; margin-left: 2px; min-width: 0; }
.ctab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  font: 600 13px/1 var(--sans);
  color: var(--ink-3);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.ctab:hover { color: var(--ink); }
.ctab[aria-selected="true"] { color: var(--ink); background: var(--bg); border-color: rgba(255, 255, 255, 0.12); }
.pnl[data-w="xs"] .ctab-label, .pnl[data-w="s"] .ctab-label, .pnl[data-w="m"] .ctab-label { display: none; }
.cpane { flex: 1 1 auto; min-height: 0; display: flex; background: var(--bg); }

.term { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; }
.term-main { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.outs { flex: 1 1 auto; min-height: 0; display: flex; }
.out {
  flex: 1;
  overflow: auto;
  padding: 10px 14px;
  font: 12.5px/1.6 var(--mono);
  color: var(--ink-2);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 4;
}
.out .pr { color: var(--ok); font-weight: 600; }
.out .err { color: #ff8f8f; }
.out .warn { color: var(--warn); }
.out .hint { color: var(--violet); }
.out .yaml { color: var(--sky); }
.out .muted { color: var(--ink-3); }
.inrow { flex: none; display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.inrow label { font: 600 13px/1 var(--mono); color: var(--ok); white-space: nowrap; }
#cmd { flex: 1; min-width: 0; min-height: 30px; border: 0; background: transparent; font: 13px var(--mono); color: var(--ink); outline: none; }
#cmd::placeholder { color: #6f6563; }
.kbtn { min-height: 28px; padding: 0 9px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, 0.14); font: 600 12px/1 var(--mono); color: var(--ink-2); background: transparent; cursor: pointer; }
.kbtn:hover { color: var(--ink); border-color: var(--line-2); }
.kbtn.stop { color: var(--danger); background: var(--danger-bg); border-color: rgba(255, 154, 174, 0.35); }
.kbtn:disabled { opacity: 0.35; cursor: default; }

.sesslist { flex: none; width: 184px; display: flex; flex-direction: column; gap: 2px; padding: 8px; overflow: auto; border-left: 1px solid rgba(255, 255, 255, 0.08); background: var(--surface); }
.sess {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 0;
  font: 600 12.5px/1.2 var(--sans);
  color: var(--ink-3);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.sess:hover { color: var(--ink); background: rgba(255, 255, 255, 0.04); }
.sess.on { color: var(--ink); background: rgba(255, 255, 255, 0.08); }
.sess i { flex: none; width: 7px; height: 7px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); }
.sess.busy i { background: var(--warn); }
.sess.unread i { background: transparent; border-radius: 50%; border: 1.5px solid var(--sky); }
.sess small { display: block; font: 500 11px/1.2 var(--mono); color: var(--ink-3); }
.sess-add { margin-top: 4px; border: 1px dashed rgba(255, 255, 255, 0.14); font-size: 12px; }
/* Узкая консоль: сеансы — строкой над выводом, а не колонкой справа. */
.pnl[data-w="xs"] .term, .pnl[data-w="s"] .term { flex-direction: column-reverse; }
.pnl[data-w="xs"] .sesslist, .pnl[data-w="s"] .sesslist {
  width: auto;
  flex-direction: row;
  border-left: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px;
  overflow-x: auto;
  overflow-y: hidden;
}
.pnl[data-w="xs"] .sess, .pnl[data-w="s"] .sess { flex: none; }
.pnl[data-w="xs"] .sess small, .pnl[data-w="s"] .sess small { display: none; }
.pnl[data-w="xs"] .sess-add, .pnl[data-w="s"] .sess-add { margin-top: 0; }

.gwrap { flex: 1 1 auto; min-width: 0; overflow: auto; padding: 10px; }
#graph { display: block; width: 100%; height: auto; }
#graph .edge { fill: none; stroke: #7c86a8; stroke-width: 2.5; }
#graph .box { stroke-width: 2.5; }
#graph .node .box { fill: var(--surface-2); stroke: var(--brand); }
#graph .topic .box { fill: var(--sky-bg); stroke: var(--sky); }
#graph .cli .box { fill: var(--violet-bg); stroke: var(--violet); stroke-dasharray: 7 5; }
#graph text { font: 600 17px var(--mono); text-anchor: middle; fill: var(--ink); }
#graph .topic text { fill: var(--sky); }
#graph .cli text { fill: var(--violet); }
/* Свой узел на Python — зелёным: «это написал я». */
#graph .pynode .box { fill: var(--ok-bg); stroke: var(--ok); }
#graph .pynode text { fill: var(--ok); }
#graph .empty { font: 500 16px var(--sans); fill: var(--ink-3); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 0 4px 8px; font-size: 12px; color: var(--ink-3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border-radius: 3px; }
.lg-n { border: 1.5px solid var(--brand); }
.lg-t { background: var(--sky-bg); border: 1.5px solid var(--sky); border-radius: 6px !important; }
.lg-c { border: 1.5px dashed var(--violet); }
.lg-p { border: 1.5px solid var(--ok); background: var(--ok-bg); }

.topics { flex: 1 1 auto; min-width: 0; overflow: auto; }
.topics table { width: 100%; border-collapse: collapse; font: 12.5px var(--mono); }
.topics th { position: sticky; top: 0; padding: 8px 14px; text-align: left; font-weight: 600; color: var(--ink-3); background: var(--bg); border-bottom: 1px solid rgba(255, 255, 255, 0.08); white-space: nowrap; }
.topics td { padding: 6px 14px; color: var(--ink-2); white-space: nowrap; }
.topics td:first-child { color: var(--sky); }
.topics-empty { padding: 16px; font-size: 13px; color: var(--ink-3); }

/* ── Куда прикрепить панель ─────────────────────────────────── */
.dg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; background: rgba(12, 9, 12, 0.45); }
.dg-head {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 8px 8px 8px 18px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 138, 92, 0.4);
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.9);
}
.dg-title { font-size: 14px; font-weight: 700; white-space: nowrap; }
.dg-hint { font-size: 13px; color: var(--ink-3); }
.dg-cancel { min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); font: 700 13px/1 var(--sans); color: var(--ink); background: #2a2230; cursor: pointer; }
.dgt {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 1px solid rgba(255, 138, 92, 0.5);
  color: var(--brand);
  background: var(--surface-2);
  cursor: pointer;
}
.dgt:hover, .dg[data-preview="top"] .dgt-top, .dg[data-preview="bottom"] .dgt-bottom, .dg[data-preview="left"] .dgt-left,
.dg[data-preview="right"] .dgt-right, .dg[data-preview="float"] .dgt-float { background: var(--brand); color: var(--brand-ink); }
.dgt-top { left: calc(50% - 28px); top: calc(50% - 94px); }
.dgt-bottom { left: calc(50% - 28px); top: calc(50% + 38px); }
.dgt-left { left: calc(50% - 94px); top: calc(50% - 28px); }
.dgt-right { left: calc(50% + 38px); top: calc(50% - 28px); }
.dgt-float { left: calc(50% - 28px); top: calc(50% - 28px); }
.dgz {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  border: 2px dashed var(--brand);
  background: rgba(255, 138, 92, 0.14);
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-2);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.dgz-top { top: 8px; left: 8px; right: 8px; }
.dgz-bottom { bottom: 8px; left: 8px; right: 8px; }
.dgz-left { top: 8px; bottom: 8px; left: 8px; }
.dgz-right { top: 8px; bottom: 8px; right: 8px; }
.dgz-float { top: calc(50% - 160px); left: calc(50% - 220px); width: 440px; height: 320px; align-items: flex-end; padding-bottom: 20px; background: rgba(255, 138, 92, 0.1); }
.dg[data-mode="click"] .dgt-top:hover ~ .dgz-top, .dg[data-mode="click"] .dgt-bottom:hover ~ .dgz-bottom,
.dg[data-mode="click"] .dgt-left:hover ~ .dgz-left, .dg[data-mode="click"] .dgt-right:hover ~ .dgz-right,
.dg[data-mode="click"] .dgt-float:hover ~ .dgz-float,
.dg[data-preview="top"] .dgz-top, .dg[data-preview="bottom"] .dgz-bottom, .dg[data-preview="left"] .dgz-left,
.dg[data-preview="right"] .dgz-right, .dg[data-preview="float"] .dgz-float { opacity: 1; }


@media (max-width: 1100px) {
  .hide-m { display: none !important; }
}
/* ── Панель «Робот»: схема с номерами и живые показания частей ── */
.ph-sub { padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; color: var(--ink-3); background: #1d1822; }
.ph-sub[data-tone="ok"] { color: var(--ok); background: var(--ok-bg); }
.ph-sub[data-tone="warn"] { color: var(--warn); background: #241b12; }
.ph-sub[data-tone="bad"] { color: var(--danger); background: var(--danger-bg); }
.robot-body { padding: 10px 12px 14px; }
.rb-svg { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto; }
.rb-cap { font: 600 11px var(--sans); fill: var(--ink-3); text-anchor: middle; letter-spacing: 0.04em; }
.rb-brush path { stroke: #3a3d44; stroke-width: 2.2; stroke-linecap: round; fill: none; }
.rb-brush circle { fill: #8b9099; }
.rb-bumper { stroke: #34373e; transition: stroke 0.15s; }
.rb-bumper.hit { stroke: #ff5a5a; }
.rb-wheel { fill: #2a2d33; stroke: #8b9099; stroke-width: 1.5; transition: stroke 0.15s, fill 0.15s; }
.rb-wheel.turn { fill: #3b2a22; stroke: var(--brand); }
.rb-roller { fill: #3a3d44; stroke: #8b9099; stroke-width: 1.5; stroke-dasharray: 4 3; }
.rb-roller.turn { stroke: var(--brand); }
.rb-chip { fill: #3a3d44; stroke: #c9a227; stroke-width: 1.5; }
.rb-contacts rect { fill: #8b9099; }
.rb-contacts.on rect { fill: #ffd166; }
.rb-svg [data-pe] { transition: filter 0.15s; }
.rb-svg .pe-on { filter: drop-shadow(0 0 3px #ff8a5c) drop-shadow(0 0 1px #ff8a5c); }
.rb-mk { cursor: pointer; }
.rb-mk line { stroke: rgba(255, 210, 190, 0.45); stroke-width: 1; }
.rb-mk .rb-mk-dot { fill: #ffd3b8; stroke: none; }
.rb-mk circle { fill: #2a2230; stroke: var(--brand); stroke-width: 1.5; }
.rb-mk text { font: 700 11px var(--sans); fill: #f7f0ea; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.rb-mk.on circle { fill: var(--brand); }
.rb-mk.on .rb-mk-dot { fill: var(--brand); }
.rb-mk.on line { stroke: var(--brand); stroke-width: 1.5; }
.rb-mk.on text { fill: #1a0f0a; }
.orgs { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.org { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.07); background: var(--surface-2); outline: none; transition: border-color 0.15s, background 0.15s; }
.org.on, .org:focus-visible { border-color: rgba(255, 138, 92, 0.55); background: #22191b; }
.org-n { flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 700; color: var(--brand); background: rgba(255, 138, 92, 0.14); }
.org.on .org-n { color: #1a0f0a; background: var(--brand); }
.org-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.org-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.org-h b { font-size: 14px; }
.org-model { font-size: 11.5px; color: var(--ink-3); }
.org-v { font: 600 12px/1.4 var(--mono); color: var(--ink); }
.org-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.chip-t { min-height: 26px; padding: 3px 8px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, 0.14); font: 600 11.5px var(--mono); color: var(--sky); background: #141217; cursor: pointer; }
.chip-t:hover { border-color: var(--brand); color: var(--brand); }
.org-nt { font-size: 11.5px; color: var(--ink-3); }
.org-viz { flex: none; }
.viz-wheels { display: flex; gap: 6px; }
.wbar { position: relative; display: block; width: 14px; height: 60px; border-radius: 5px; background: #121014; border: 1px solid rgba(255, 255, 255, 0.1); overflow: hidden; }
.wbar::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(255, 255, 255, 0.25); }
.wbar i { position: absolute; left: 2px; right: 2px; top: 50%; height: 0; border-radius: 3px; background: var(--brand); }
.wbar em { position: absolute; left: 0; right: 0; bottom: -1px; font: 700 9px var(--sans); font-style: normal; text-align: center; color: var(--ink-3); }
.viz-compass { width: 56px; height: 56px; }
.cmp-ring { fill: #121014; stroke: rgba(255, 255, 255, 0.18); stroke-width: 1.5; }
.cmp-n { font: 700 8px var(--sans); fill: var(--ink-3); text-anchor: middle; }
.cmp-needle { fill: var(--brand); }
.cmp-hub { fill: #eceef1; }
.viz-compass.off .cmp-needle { fill: #55575d; }
.pnl[data-w="xs"] .org-viz { display: none; }

/* Телефон: полоса состояния над картой — короче. */
@media (max-width: 640px) {
  .stage { top: 52px; }
  .hud { padding: 3px; }
  .hud-m { padding: 5px 6px; font-size: 12px; }
  .hud-bar, .hud-map, .hud-sel-t { display: none; }
  .hud-state { padding: 5px 8px; font-size: 12px; }
  .status { max-width: calc(100% - 24px); bottom: 56px; }
  .zoom .ib { width: 32px; height: 32px; }
}

/* ── Панель «Код»: свои узлы на Python ──────────────────────── */
.code-body { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.cfiles { flex: none; display: flex; align-items: center; gap: 4px; padding: 6px 8px; overflow-x: auto; overflow-y: hidden; background: var(--surface); border-bottom: 1px solid rgba(255, 255, 255, 0.08); scrollbar-width: thin; }
.cfile { flex: none; display: flex; align-items: center; border-radius: 8px; border: 1px solid transparent; }
.cfile.on { background: var(--bg); border-color: rgba(255, 255, 255, 0.14); }
.cfile-name { display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 0 10px; border: 0; border-radius: 8px; font: 600 12.5px/1 var(--mono); color: var(--ink-3); background: transparent; cursor: pointer; white-space: nowrap; }
.cfile-name:hover, .cfile.on .cfile-name { color: var(--ink); }
.cfile-name i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.16); }
.cfile.run .cfile-name i { background: var(--ok); box-shadow: 0 0 0 3px rgba(111, 220, 171, 0.18); }
.cfile.bad .cfile-name i { background: #ff8f8f; }
.cfile-del { min-height: 30px; min-width: 26px; padding: 0 8px 0 2px; border: 0; border-radius: 8px; font: 600 15px/1 var(--sans); color: var(--ink-3); background: transparent; cursor: pointer; }
.cfile-del:hover { color: var(--danger); }
.cfile-del.confirm { font: 700 11.5px/1 var(--sans); color: var(--danger); }
.cfile-add { flex: none; min-height: 30px; min-width: 32px; border-radius: 8px; border: 1px dashed rgba(255, 255, 255, 0.18); font: 600 16px/1 var(--sans); color: var(--ink-3); background: transparent; cursor: pointer; }
.cfile-add:hover { color: var(--ink); border-color: var(--line-2); }
.cfile-new { flex: none; width: 150px; min-height: 30px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--violet); font: 12.5px var(--mono); color: var(--ink); background: var(--bg); outline: none; }
.cfile-new[aria-invalid="true"] { border-color: #ff8f8f; }
.cedit { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.cedit textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 10px 14px;
  border: 0;
  resize: none;
  outline: none;
  font: 13px/1.6 var(--mono);
  color: var(--ink);
  background: var(--bg);
  white-space: pre;
  overflow: auto;
  tab-size: 4;
  -moz-tab-size: 4;
}
.cempty { flex: 1; margin: 0; padding: 18px; font-size: 13px; color: var(--ink-3); }
.cerr { flex: none; display: block; width: 100%; padding: 7px 14px; border: 0; border-top: 1px solid rgba(255, 143, 143, 0.35); font: 600 12px/1.45 var(--mono); text-align: left; color: #ffb3b3; background: var(--danger-bg); cursor: pointer; overflow-wrap: anywhere; }
.cerr:hover { color: #ffd0d0; }
.cbar { flex: none; display: flex; align-items: center; gap: 10px; min-width: 0; padding: 7px 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); background: var(--surface); }
.crun { flex: none; display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 0 14px; border-radius: 999px; border: 0; font: 700 13px/1 var(--sans); color: var(--brand-ink); background: linear-gradient(135deg, #8ff0c4, #3fbf86); cursor: pointer; }
.crun:hover { filter: brightness(1.07); }
.crun:disabled { opacity: 0.4; cursor: default; }
.crun .i-stop { display: none; }
.crun.stop { color: var(--danger); background: var(--danger-bg); box-shadow: inset 0 0 0 1px rgba(255, 154, 174, 0.4); }
.crun.stop .i-stop { display: block; }
.crun.stop .i-play { display: none; }
.ccmd { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px var(--mono); color: var(--ink-3); }
.creset { flex: none; min-height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid rgba(185, 156, 255, 0.4); font: 600 12px/1 var(--sans); color: var(--ink-2); background: transparent; cursor: pointer; white-space: nowrap; }
.creset:hover { color: var(--ink); border-color: var(--violet); }
.creset.confirm { color: var(--warn); border-color: rgba(242, 181, 113, 0.6); }
.cstate { flex: none; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.cstate[data-tone="warn"] { color: var(--warn); white-space: normal; }
.pnl[data-w="xs"] .ccmd, .pnl[data-w="xs"] .cstate, .pnl[data-w="s"] .cstate { display: none; }
.pnl[data-w="xs"] .cstate[data-tone="warn"], .pnl[data-w="s"] .cstate[data-tone="warn"] { display: block; flex: 1 1 auto; min-width: 0; }

/* CodeMirror в гамме страницы (тему с CDN не тянем — своя короче). */
.cedit .CodeMirror { position: absolute; top: 0; right: 0; bottom: 0; left: 0; height: 100%; font: 13px/1.6 var(--mono); color: var(--ink); background: var(--bg); }
.cedit .CodeMirror-gutters { background: var(--surface); border-right: 1px solid rgba(255, 255, 255, 0.07); }
.cedit .CodeMirror-linenumber { color: #6f6563; }
.cedit .CodeMirror-cursor { border-left: 2px solid var(--brand); }
.cedit .CodeMirror-selected { background: rgba(185, 156, 255, 0.2); }
.cedit .CodeMirror-focused .CodeMirror-selected, .cedit .CodeMirror-line::selection, .cedit .CodeMirror-line > span::selection, .cedit .CodeMirror-line > span > span::selection { background: rgba(185, 156, 255, 0.3); }
.cedit .CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.03); }
.cedit .cm-py-err { background: rgba(255, 110, 110, 0.16); }
.cedit .cm-s-default .cm-keyword { color: #ff8a5c; }
.cedit .cm-s-default .cm-def { color: #93bdff; }
.cedit .cm-s-default .cm-variable { color: var(--ink); }
.cedit .cm-s-default .cm-variable-2 { color: #e8d9ff; }
.cedit .cm-s-default .cm-property { color: #c6bab5; }
.cedit .cm-s-default .cm-string { color: #6fdcab; }
.cedit .cm-s-default .cm-number { color: #f2b571; }
.cedit .cm-s-default .cm-comment { color: #8a7f7c; font-style: italic; }
.cedit .cm-s-default .cm-builtin { color: #b99cff; }
.cedit .cm-s-default .cm-operator { color: #f7f0ea; }
.cedit .cm-s-default .cm-meta { color: #f2b571; }
.cedit .cm-s-default .cm-atom { color: #f2b571; }
.cedit .cm-s-default .cm-error { color: #ff8f8f; }
