:root {
  --bg: #0a1017;
  --panel: #121c27;
  --panel-2: #182634;
  --line: #243546;
  --text: #e6edf5;
  --muted: #8ba0b5;
  --accent: #38d6c0;
  --accent-2: #4da3ff;
  --warn: #ffcc66;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 700px at 70% -10%, #163243 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
}

.app { max-width: 1220px; margin: 0 auto; padding: 22px 20px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 46px; height: 46px; display: grid; place-items: center;
  font-size: 24px; border-radius: 13px;
  background: linear-gradient(145deg, #1e4a55, #122a35);
  border: 1px solid #2b6570;
  box-shadow: 0 0 22px rgba(56, 214, 192, .12);
}
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.status-pill {
  display: flex; align-items: center; gap: 9px; padding: 8px 14px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.status-pill .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--muted);
  box-shadow: 0 0 0 4px rgba(139, 160, 181, .12);
}
.status-pill.running .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(56, 214, 192, .16); }
.status-pill.charging .dot { background: var(--warn); box-shadow: 0 0 0 4px rgba(255, 204, 102, .16); }
.status-pill.low .dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 107, 107, .16); }

.layout { display: grid; grid-template-columns: 316px minmax(0, 1fr); gap: 18px; align-items: start; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
}
.block { padding: 15px 16px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: none; }
.block h2 {
  margin: 0 0 11px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .9px; color: var(--muted); font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
}
.value { color: var(--accent); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }

.btn-row { display: flex; gap: 8px; }
.btn {
  flex: 1; padding: 10px 8px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 13px; font-weight: 600; transition: .15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary {
  background: linear-gradient(145deg, #2fbfaa, #1c8f86);
  border-color: #35c9b5; color: #062522;
}
.btn-primary.paused {
  background: linear-gradient(145deg, #ffcf72, #e0a63c);
  border-color: #ffcf72; color: #3a2a05;
}
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; margin-top: 8px; }
#btnDock.active { border-color: var(--warn); color: var(--warn); }

.mode-grid, .brush-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-btn, .brush-btn {
  display: flex; gap: 7px; align-items: center; justify-content: center;
  padding: 9px 6px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); font-size: 12px; font-weight: 600; transition: .15s ease;
}
.mode-btn { flex-direction: column; gap: 3px; font-size: 18px; padding: 9px 4px; }
.mode-btn span, .brush-btn { font-size: 12px; }
.mode-btn:hover, .brush-btn:hover { border-color: var(--accent); color: var(--text); }
.mode-btn.active, .brush-btn.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(56, 214, 192, .09);
}

input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; margin: 7px 0; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.stat-line { display: flex; justify-content: space-between; color: var(--muted); margin: 9px 0 5px; }
.stat-line strong { color: var(--text); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 99px; background: #0b141d; overflow: hidden; border: 1px solid #1d2c3a; }
.bar-fill { height: 100%; width: 0; border-radius: 99px; transition: width .2s linear; }
.bar-fill.battery { background: linear-gradient(90deg, #38d6c0, #7ce8a0); }
.bar-fill.clean { background: linear-gradient(90deg, #4da3ff, #38d6c0); }
.bar-fill.low { background: linear-gradient(90deg, #ff6b6b, #ffcc66); }

/* --- Ручное управление (D-pad) --- */
.d-pad {
  display: grid;
  grid-template-columns: 55px 55px 55px;
  grid-template-rows: 55px 55px 55px;
  gap: 8px;
  justify-content: center;
  margin: 12px 0;
}
.dp-up    { grid-column: 2; grid-row: 1; }
.dp-left  { grid-column: 1; grid-row: 2; }
.dp-stop  { grid-column: 2; grid-row: 2; }
.dp-right { grid-column: 3; grid-row: 2; }
.dp-down  { grid-column: 2; grid-row: 3; }

.dp-btn {
  width: 55px; height: 55px;
  border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font-size: 22px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  transition: .15s ease;
}
.dp-btn:hover { border-color: var(--accent); background: rgba(56,214,192,.12); }
.dp-btn:active { background: var(--accent); color: #062522; }
.dp-stop {
  background: var(--danger); color: #fff; border-color: var(--danger);
}
.dp-stop:hover { background: var(--danger); opacity: .9; }

.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
kbd {
  display: inline-block; padding: 1px 5px; margin: 0 1px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 11px;
}

.log-block { padding-bottom: 10px; }
.log-list { list-style: none; margin: 0; padding: 0; max-height: 154px; overflow-y: auto; }
.log-list li { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px dashed #1f2c39; font-size: 12px; }
.log-list li:last-child { border-bottom: none; }
.log-list time { color: #5f7b92; font-variant-numeric: tabular-nums; flex: none; }
.log-list span { color: #b9c9d8; }

.stage { min-width: 0; }
.stage-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 10px; font-size: 12px;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-robot { background: #7fd8e6; border-radius: 50%; }
.sw-dirt { background: #8a6338; }
.sw-wall { background: #2b3644; }
.sw-obstacle { background: #5d4b3d; }
.sw-dock { background: #56d98a; border-radius: 50%; }

.canvas-wrap {
  background: #0d151e; border: 1px solid var(--line); border-radius: 14px;
  padding: 8px; box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
canvas { display: block; width: 100%; height: auto; border-radius: 8px; cursor: crosshair; }

/* --- Подключение к реальному роботу --- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 3px; background: #0c1520; border: 1px solid var(--line); border-radius: 10px; }
.seg-btn { padding: 8px 4px; border: none; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--panel-2); color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.field { display: block; margin-top: 12px; color: var(--muted); font-size: 12px; }
.field input {
  width: 100%; margin-top: 5px; padding: 9px 10px; border-radius: 8px;
  background: #0c1520; border: 1px solid var(--line); color: var(--text); font: 12px Consolas, monospace;
}
.field input:focus { outline: none; border-color: var(--accent); }
.conn-state { margin: 9px 0 0; font-size: 12px; color: var(--muted); }
.conn-state.on { color: var(--accent); }
.conn-state.err { color: var(--danger); }

.live-card {
  background: linear-gradient(150deg, #142532, #0e1922);
  border: 1px solid var(--line); border-radius: 14px; padding: 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35); min-height: 448px;
}
.live-head { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 5px rgba(139,160,181,.1); }
.live-card.online .live-dot { background: var(--accent); box-shadow: 0 0 0 5px rgba(56,214,192,.14); animation: pulse 2s infinite; }
.live-badge { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; }
.live-updated { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.live-bar { margin: -6px 0 20px; height: 8px; }
.live-refresh {
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--accent); font-size: 16px; cursor: pointer; line-height: 1;
}
.live-refresh:hover { border-color: var(--accent); background: rgba(56,214,192,.12); }
.map-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 11px; color: var(--muted); }
.map-legend span { display: flex; align-items: center; gap: 5px; }
.map-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.map-wall { background: #2b3644; }
.map-floor { background: #152733; border: 1px solid #2a4050; }
.map-robot { background: #ff6b6b; border-radius: 50% !important; }
.map-path { background: #38d6c0; height: 2px !important; border-radius: 2px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px rgba(56,214,192,0); } }
.live-main { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 32px 0 24px; }
.live-main > div { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 11px; padding: 16px; }
.live-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; margin-bottom: 7px; }
.live-main strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.live-map-wrap { margin: 14px 0 18px; }
.live-map-head { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; margin-bottom: 8px; }
#liveMap { display: block; width: 100%; height: auto; border-radius: 9px; background: #0a1219; border: 1px solid var(--line); }
.live-extra { color: var(--muted); font-size: 13px; line-height: 1.6; border-top: 1px solid var(--line); padding-top: 16px; }
.raw-cmd { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.raw-title { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; margin-bottom: 8px; }
.raw-row { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 6px; }
.raw-row input {
  min-width: 0; width: 100%; padding: 8px; border-radius: 7px;
  background: #0c1520; border: 1px solid var(--line); color: var(--text); font: 12px Consolas, monospace;
}
.raw-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.raw-chips button {
  padding: 3px 7px; border-radius: 5px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font: 11px Consolas, monospace; cursor: pointer;
}
.raw-chips button:hover { border-color: var(--accent); color: var(--accent); }
.raw-chips button.known { border-color: rgba(56, 214, 192, .55); color: var(--accent); }
.live-extra.error { color: var(--danger); }

body.live .canvas-wrap, body.live #simHint { display: none; }
body.live #liveCard { display: block; }
body.live #speedBlock, body.live #displayBlock, body.live #editorBlock { display: none; }

@media (max-width: 600px) {
  .live-main { grid-template-columns: 1fr; }
} 

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .stage { order: -1; }
}
