:root {
  --desktop: #7e8895;
  --desktop-dark: #636d7a;
  --panel: #f2f5f9;
  --panel-2: #e7edf4;
  --panel-3: #dce5ee;
  --line: #8496a9;
  --line-soft: #c6d2de;
  --title-top: #edf5fe;
  --title-bottom: #a9c9e8;
  --title-ink: #23384d;
  --accent: #2d6fce;
  --accent-dark: #1f569f;
  --gold: #f2c94c;
  --danger: #c93b3b;
  --danger-dark: #9f2929;
  --green: #2e9e4f;
  --ink: #202a35;
  --ink-soft: #526174;
  --comment-background: #fff6c9;
  --comment-text: #5b4c13;
  --shadow: 0 8px 24px rgba(20, 35, 52, 0.22);
  --radius: 9px;
  --step: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Tahoma, sans-serif;
  font-size: 13px;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.12), transparent 34%),
    linear-gradient(160deg, #8b95a2, #707b88 58%, #626d79);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.hidden {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.menubar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 43px;
  padding: 0 12px;
  color: #f7fbff;
  background: linear-gradient(180deg, #4c5a6b, #394452 58%, #303947);
  border-bottom: 1px solid #232b36;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 148px;
  user-select: none;
}

.brand-robot {
  width: 27px;
  height: 27px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 15px;
}

.brand-web {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #20384f;
  background: linear-gradient(#f8fcff, #b9d9f5);
  border: 1px solid #8eb6da;
  border-radius: 4px;
  padding: 1px 4px;
}

.menu-bar {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 1px;
}

.menu {
  position: relative;
  display: flex;
  align-items: center;
}

.menu-title {
  height: 100%;
  border: 0;
  padding: 0 11px;
  color: #f2f7fc;
  background: transparent;
  border-radius: 4px;
  font-size: 12.5px;
}

.menu-title:hover,
.menu.open .menu-title {
  background: rgba(255, 255, 255, 0.16);
}

.dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 258px;
  padding: 5px;
  background: linear-gradient(#fbfdff, #eef3f8);
  border: 1px solid #708399;
  border-radius: 7px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  z-index: 100;
}

.menu.open > .dropdown {
  display: block;
}

.dropdown button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  border-radius: 4px;
  padding: 6px 9px;
  background: transparent;
  text-align: left;
  color: #1e2b39;
}

.dropdown button:hover:not(:disabled) {
  background: linear-gradient(#5c9be0, #2f73c6);
  color: #fff;
}

.dropdown .shortcut {
  color: #7a8897;
  font-size: 11px;
  margin-left: 24px;
}

.dropdown button:hover .shortcut {
  color: rgba(255, 255, 255, 0.8);
}

.dropdown .sep {
  height: 1px;
  margin: 5px 6px;
  background: #c9d4df;
}

.menubar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  border: 1px solid #7d9ab9;
  border-radius: 999px;
  padding: 4px 11px;
  background: linear-gradient(#f9fcff, #c7def4);
  color: #1e3a55;
  font-size: 11.5px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.pill:hover {
  background: linear-gradient(#ffffff, #b7d5ef);
}

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 196px minmax(420px, 1.18fr) minmax(350px, 0.92fr);
  gap: 9px;
  padding: 9px 10px 8px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid #6f8195;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-title {
  flex: 0 0 31px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: linear-gradient(180deg, var(--title-top), var(--title-bottom));
  border-bottom: 1px solid #7d99b6;
  color: var(--title-ink);
  user-select: none;
}

.traffic {
  display: flex;
  gap: 4px;
  margin-right: 2px;
}

.traffic span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.28);
  background: radial-gradient(circle at 35% 30%, #fff9, transparent 60%), #e35656;
}

.traffic span:nth-child(2) {
  background: radial-gradient(circle at 35% 30%, #fff9, transparent 60%), #e8b93d;
}

.traffic span:nth-child(3) {
  background: radial-gradient(circle at 35% 30%, #fff9, transparent 60%), #55b94f;
}

.panel-title-text {
  font-weight: 700;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-title-sub {
  margin-left: auto;
  font-size: 11px;
  color: #325a7d;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 1px 7px;
}

.title-actions {
  margin-left: auto;
  display: flex;
  gap: 5px;
}

.mini-btn {
  border: 1px solid #7d9bb9;
  border-radius: 4px;
  background: linear-gradient(#fcfdff, #d9e8f6);
  padding: 2px 7px;
  font-size: 11px;
  color: #24415d;
}

.mini-btn:hover {
  background: linear-gradient(#ffffff, #c6ddf1);
}

.palette {
  min-height: 0;
}

.tool-grid {
  flex: 0 1 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px 9px 6px;
  overflow-y: auto;
}

.tool-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 58px;
  padding: 4px;
  border: 1px solid #a9b8c8;
  border-radius: 7px;
  background: linear-gradient(#ffffff, #e7eef6);
  box-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(32, 50, 70, 0.12);
  color: #26384b;
}

.tool-btn:hover {
  border-color: #6d94bd;
  background: linear-gradient(#ffffff, #d6e8f8);
}

.tool-btn.active {
  border-color: #2d6fce;
  background: linear-gradient(#e8f2ff, #bcd9f7);
  box-shadow: 0 0 0 2px rgba(45, 111, 206, 0.28), inset 0 1px 0 #fff;
}

.tool-btn .tool-icon {
  width: 30px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.tool-btn .tool-label {
  font-size: 9px;
  line-height: 1.05;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tool-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 17px;
  padding: 0 3px;
  border: 1.5px solid #2c3540;
  background: #fff;
  border-radius: 3px;
  font-size: 9px;
  line-height: 1;
}

.tool-glyph.oval {
  border-radius: 999px;
}

.tool-glyph.hex {
  clip-path: polygon(12% 0, 88% 0, 100% 50%, 88% 100%, 12% 100%, 0 50%);
  border: 0;
  background: #2c3540;
  color: #fff;
}

.tool-glyph.loop {
  position: relative;
  width: 26px;
  height: 22px;
  border-width: 1.5px;
  background: #fff;
}

.tool-glyph.loop::after {
  content: "Fin";
  position: absolute;
  bottom: 1px;
  left: 2px;
  font-size: 5px;
  color: #2c3540;
}

.tool-glyph.comment {
  background: var(--comment-background);
  border-style: dashed;
}

.tool-glyph.eraser {
  border: 0;
  background: linear-gradient(135deg, #f39ac0 0 50%, #ffffff 50% 100%);
  transform: rotate(-18deg);
  border-radius: 2px;
}

.palette-hint {
  flex: 0 0 auto;
  min-height: 52px;
  margin: 0 9px 9px;
  padding: 7px 8px;
  border: 1px solid #ccd7e2;
  border-radius: 6px;
  background: #fbfcfe;
  color: #526274;
  font-size: 10.5px;
  line-height: 1.3;
}

.program-window {
  position: relative;
}

.program-tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  min-height: 0;
  padding: 0 6px;
  background: linear-gradient(#dce8f4, #cbdcee);
  border-bottom: 1px solid #9db3c9;
  overflow-x: auto;
}

.program-tabs:empty {
  display: none;
}

.program-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 190px;
  padding: 5px 9px;
  border: 1px solid #9fb4c9;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(#f6faff, #dbe8f5);
  color: #26394c;
  font-size: 11px;
  white-space: nowrap;
}

.program-tab.active {
  background: var(--panel);
  color: #102536;
  font-weight: 600;
  box-shadow: 0 -2px 4px rgba(40, 70, 100, 0.08);
}

.program-tab .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.program-tab .tab-add {
  border: 1px dashed #8fa7bd;
  background: transparent;
  color: #3b5d7c;
  border-radius: 5px;
  padding: 2px 7px;
  margin-bottom: 3px;
}

.program-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: linear-gradient(#f7fafd, #e8eff7);
  border-bottom: 1px solid #c4d1de;
}

.robot-avatar,
.exec-robot {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 28%, #ffffff, #d7e6f4 62%, #a8bfd5);
  border: 1px solid #879cb2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 2px #fff;
}

.robot-avatar svg,
.exec-robot svg {
  width: 34px;
  height: 34px;
}

.robot-avatar img,
.exec-robot img {
  width: 31px;
  height: 37px;
  object-fit: contain;
  display: block;
}

.program-head {
  min-width: 0;
  flex: 1 1 auto;
}

.program-name {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1f3448;
}

.objective-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.objective-row label {
  font-size: 11px;
  color: #596b7d;
}

.objective-row select {
  max-width: 210px;
  height: 22px;
  padding: 1px 4px;
  border: 1px solid #9eb1c4;
  border-radius: 4px;
  background: #fff;
  font-size: 11px;
}

.icon-btn {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #a5b7c8;
  border-radius: 4px;
  background: linear-gradient(#ffffff, #e4edf6);
  color: #2a4662;
  font-weight: 700;
  font-size: 12px;
  padding: 0;
}

.icon-btn:hover {
  background: linear-gradient(#ffffff, #d3e5f6);
}

.view-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.program-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  position: relative;
  background: #fff;
}

.sub-list {
  flex: 0 0 158px;
  overflow-y: auto;
  padding: 6px;
  background: linear-gradient(#f5f9fd, #e8f0f8);
  border-right: 1px solid #b9c9d8;
}

.sub-item {
  padding: 6px 7px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.sub-item:hover {
  background: rgba(45, 111, 206, 0.09);
}

.sub-item.active {
  background: linear-gradient(#d5e7fa, #b9d5f0);
  border-color: #7da5cc;
  font-weight: 600;
}

.sub-item.main {
  border-bottom: 1px solid #c7d3df;
  margin-bottom: 6px;
  padding-bottom: 8px;
}

.flow-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.flow-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: #fbfcfe;
  scrollbar-color: #a9bacb #e7edf4;
}

.flow-surface {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  background-color: #ffffff;
  background-image:
    linear-gradient(to right, rgba(45, 111, 206, 0.16) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, rgba(45, 111, 206, 0.16) 0.5px, transparent 0.5px),
    linear-gradient(to right, rgba(45, 111, 206, 0.055) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, rgba(45, 111, 206, 0.055) 0.5px, transparent 0.5px);
  background-size:
    calc(var(--step) * 5) calc(var(--step) * 5),
    calc(var(--step) * 5) calc(var(--step) * 5),
    var(--step) var(--step),
    var(--step) var(--step);
  background-position:
    0 0,
    0 0,
    0 0,
    0 0;
  cursor: default;
}

.flow-surface.tool-begin,
.flow-surface.tool-end,
.flow-surface.tool-move,
.flow-surface.tool-turnLeft,
.flow-surface.tool-turnRight,
.flow-surface.tool-test,
.flow-surface.tool-call,
.flow-surface.tool-assign,
.flow-surface.tool-io,
.flow-surface.tool-cmd,
.flow-surface.tool-comment,
.flow-surface.tool-while,
.flow-surface.tool-for,
.flow-surface.tool-mark,
.flow-surface.tool-unmark,
.flow-surface.tool-recharge {
  cursor: crosshair;
}

.flow-surface.tool-erase {
  cursor: not-allowed;
}

.flow-surface.tool-link {
  cursor: alias;
}

.link-layer,
.preview-layer,
.block-layer {
  position: absolute;
  inset: 0;
}

.link-layer {
  overflow: visible;
  pointer-events: none;
}

.preview-layer {
  pointer-events: none;
}

.link-layer .link-path {
  fill: none;
  stroke: #1d252e;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.link-layer .link-path.selected {
  stroke: var(--accent);
  stroke-width: 2.6;
}

.link-layer .link-hit {
  fill: none;
  stroke: rgba(0, 0, 0, 0);
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}

.link-layer .arrow-fill {
  fill: #1d252e;
}

.link-preview {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  stroke-linejoin: round;
}

.block-layer {
  pointer-events: none;
}

.flow-block {
  position: absolute;
  pointer-events: auto;
  user-select: none;
  color: #161d25;
  background: #fff;
  border: 2px solid #20262e;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(20, 30, 45, 0.08);
  transition: box-shadow 0.08s;
}

.flow-block.shape-round {
  border-radius: 999px;
}

.flow-block.shape-test,
.flow-block.shape-io {
  border: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}

.flow-block.shape-loop {
  border-radius: 10px;
  background: #fbfdff;
  border-width: 2px;
}

.flow-block.shape-comment {
  border-style: dashed;
  border-color: #9a8640;
  background: var(--comment-background);
  color: var(--comment-text);
  box-shadow: 2px 3px 0 rgba(120, 100, 25, 0.12);
}

.flow-block.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(45, 111, 206, 0.14);
}

.flow-block.block-error {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(201, 59, 59, 0.16);
}

.block-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.block-outline-path {
  fill: #fff;
  stroke: #20262e;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.block-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  text-align: center;
  font-size: 12px;
  line-height: 1.15;
  overflow: hidden;
  word-break: break-word;
  pointer-events: none;
}

.flow-block.shape-test .block-text {
  padding-left: 16%;
  padding-right: 16%;
}

.flow-block.shape-io .block-text {
  padding-left: 12%;
}

.loop-header,
.loop-footer {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.loop-header {
  top: 0;
  border-bottom: 2px solid #20262e;
  border-radius: 8px 8px 0 0;
  background: #fff;
}

.loop-body {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(2.6 * var(--step));
  bottom: calc(2.2 * var(--step));
  border-left: 1px dashed rgba(45, 111, 206, 0.45);
  border-right: 1px dashed rgba(45, 111, 206, 0.45);
  background:
    repeating-linear-gradient(0deg, transparent, transparent calc(var(--step) - 1px), rgba(45, 111, 206, 0.06) calc(var(--step) - 1px), rgba(45, 111, 206, 0.06) var(--step)),
    repeating-linear-gradient(90deg, transparent, transparent calc(var(--step) - 1px), rgba(45, 111, 206, 0.06) calc(var(--step) - 1px), rgba(45, 111, 206, 0.06) var(--step));
  pointer-events: none;
}

.loop-footer {
  bottom: 0;
  border-top: 2px solid #20262e;
  border-radius: 0 0 8px 8px;
  background: #f1f5fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #425568;
}

.block-text.loop-text {
  inset: 0 0 auto 0;
  height: calc(2.6 * var(--step));
  padding: 4px 14px;
  font-weight: 600;
}

.port {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: #fff;
  z-index: 8;
  opacity: 0.55;
  transition: opacity 0.1s, transform 0.1s;
}

.port:hover {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.25);
}

.port.port-y,
.port.port-n {
  width: 15px;
  height: 15px;
  font-size: 8px;
  font-weight: 700;
  color: #1f4e88;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.port.port-in {
  background: #e9f2fc;
}

.port.port-back {
  background: #e9f2fc;
}

.port.port-body,
.port.port-exit {
  background: #dceafd;
}

.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 1px;
  z-index: 5;
}

.handle-left {
  left: -5px;
  top: 25%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.handle-right {
  right: -5px;
  top: 75%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.handle-top {
  top: -5px;
  left: 25%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.handle-bottom {
  bottom: -5px;
  left: 75%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.block-editor {
  position: absolute;
  z-index: 20;
  resize: none;
  border: 2px solid var(--accent);
  border-radius: 4px;
  padding: 3px 6px;
  background: #fff;
  color: #17212b;
  outline: none;
  box-shadow: 0 0 0 3px rgba(45, 111, 206, 0.16);
  line-height: 1.15;
}

.selection-rect {
  position: absolute;
  border: 1px dashed var(--accent);
  background: rgba(45, 111, 206, 0.1);
}

.flow-empty-hint {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 20px;
  color: #7e8d9e;
  background: rgba(255, 255, 255, 0.82);
  border: 1px dashed #b9c8d8;
  border-radius: 8px;
  pointer-events: none;
  font-size: 11.5px;
  text-align: center;
}

.flow-empty-hint strong {
  font-size: 13px;
  color: #5b6e82;
}

.program-footer {
  flex: 0 0 30px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: linear-gradient(#eef4fa, #dbe6f1);
  border-top: 1px solid #b7c7d6;
}

.footer-btn {
  border: 1px solid #9cafc2;
  border-radius: 4px;
  background: linear-gradient(#ffffff, #e0eaf4);
  padding: 2px 8px;
  font-size: 11px;
  color: #25405a;
}

.footer-btn:hover {
  background: linear-gradient(#ffffff, #d1e3f3);
}

.footer-btn.active {
  background: linear-gradient(#d3e7fb, #aecff0);
  border-color: #6e9bc5;
}

.flow-status {
  margin-left: auto;
  color: #607184;
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.execution-window {
  position: relative;
}

.exec-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 6px 7px;
  background: linear-gradient(#f7fafd, #e6eef6);
  border-bottom: 1px solid #c4d1de;
}

.exec-btn {
  border: 1px solid #93a9bf;
  border-radius: 5px;
  padding: 4px 8px;
  background: linear-gradient(#ffffff, #dce8f4);
  color: #233d58;
  font-size: 11px;
  font-weight: 600;
}

.exec-btn:hover:not(:disabled) {
  background: linear-gradient(#ffffff, #c9dff2);
}

.exec-btn.active {
  background: linear-gradient(#bcd9f7, #8fbfe9);
  border-color: #4e86bc;
}

.exec-btn.init-btn {
  min-width: 42px;
  background: linear-gradient(#f9fdff, #cfe3f5);
}

.exec-btn.run-btn {
  background: linear-gradient(#e7f9e9, #bce6c2);
  border-color: #6cae78;
  color: #1e5a2a;
}

.exec-btn.stop-btn {
  background: linear-gradient(#fff0f0, #f1c7c7);
  border-color: #bd7d7d;
  color: #7d2525;
}

.exec-robot {
  width: 30px;
  height: 30px;
  margin: 0 2px;
}

.exec-robot svg {
  width: 27px;
  height: 27px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  font-size: 10px;
  color: #4c6075;
  white-space: nowrap;
}

.speed-control input {
  width: 76px;
  accent-color: var(--accent);
}

.exec-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 180px;
  overflow: hidden;
  background: #244b72;
}

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

.exec-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  color: #eaf3fc;
  text-align: center;
  background: rgba(15, 31, 47, 0.58);
  font-size: 12.5px;
  line-height: 1.4;
  z-index: 3;
}

.exec-overlay .overlay-card {
  max-width: 460px;
  padding: 16px 18px;
  background: rgba(241, 247, 253, 0.96);
  color: #223447;
  border: 1px solid #8ea9c2;
  border-radius: 9px;
  box-shadow: var(--shadow);
}

.exec-overlay .overlay-card h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #183d61;
}

.exec-overlay .overlay-card p {
  margin: 4px 0;
}

.round-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 24, 38, 0.6);
}

.round-card {
  width: min(440px, 86%);
  padding: 16px 18px;
  background: #f4f9fe;
  border: 1px solid #8ea9c2;
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: #223447;
}

.round-card h3 {
  margin: 0 0 8px;
  color: #183d61;
  font-size: 15px;
}

.round-card .round-scores {
  margin: 8px 0 12px;
  display: grid;
  gap: 4px;
}

.round-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 7px;
  border-radius: 4px;
  background: rgba(45, 111, 206, 0.08);
}

.round-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.round-card .actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.exec-status {
  flex: 0 0 auto;
  min-height: 24px;
  padding: 4px 8px;
  color: #3f5368;
  background: #eef4fa;
  border-top: 1px solid #c1cfdd;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.console-panel {
  flex: 0 0 auto;
  max-height: 38%;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #8ca2b8;
  background: #0f1720;
  color: #d7e4ef;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 7px;
  background: #223244;
  font-size: 11px;
  font-weight: 600;
}

.console-head .icon-btn {
  width: 18px;
  height: 18px;
  color: #d7e4ef;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.console-output {
  flex: 1 1 auto;
  min-height: 54px;
  max-height: 150px;
  margin: 0;
  padding: 7px 9px;
  overflow: auto;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.console-form {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.console-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid #4a6076;
  border-radius: 3px;
  background: #1b2938;
  color: #f2f8ff;
}

.console-form button {
  border: 1px solid #5b7893;
  border-radius: 3px;
  padding: 3px 8px;
  background: #2b455e;
  color: #eef6ff;
}

.console-hint {
  padding: 0 9px 5px;
  color: #7e93a7;
  font-size: 10px;
}

.statusbar {
  flex: 0 0 25px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 10px;
  color: #e8f0f8;
  background: linear-gradient(#485565, #333d49);
  border-top: 1px solid #252d37;
  font-size: 10.5px;
  white-space: nowrap;
}

#statusMode {
  font-weight: 600;
}

#statusHint {
  overflow: hidden;
  text-overflow: ellipsis;
  color: #c5d3e1;
}

#statusCoords {
  margin-left: auto;
  color: #a9bccd;
  font-variant-numeric: tabular-nums;
}

#modalRoot:empty {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(18, 28, 40, 0.46);
  backdrop-filter: blur(1.5px);
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(620px, 96vw);
  max-height: 92vh;
  background: var(--panel);
  border: 1px solid #5e748a;
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.modal.small {
  width: min(430px, 96vw);
}

.modal.large {
  width: min(980px, 97vw);
}

.modal.xlarge {
  width: min(1180px, 98vw);
  height: min(870px, 94vh);
}

.modal-header {
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 9px;
  background: linear-gradient(180deg, var(--title-top), var(--title-bottom));
  border-bottom: 1px solid #7d99b6;
  font-weight: 700;
  color: var(--title-ink);
}

.modal-title {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-close {
  width: 22px;
  height: 22px;
  border: 1px solid #8da3b9;
  border-radius: 4px;
  background: linear-gradient(#fff, #dbe8f5);
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px;
  background: #f8fbfe;
}

.modal-body p {
  margin: 0 0 9px;
  line-height: 1.45;
}

.modal-body ul,
.modal-body ol {
  margin: 6px 0 10px;
  padding-left: 22px;
  line-height: 1.45;
}

.modal-body h3,
.modal-body h4 {
  margin: 14px 0 7px;
  color: #173c60;
}

.modal-body code {
  padding: 1px 4px;
  border-radius: 3px;
  background: #e7eef6;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.94em;
}

.modal-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  padding: 9px 12px;
  background: linear-gradient(#eef4fa, #dbe6f1);
  border-top: 1px solid #b7c7d6;
}

.btn {
  border: 1px solid #8fa5ba;
  border-radius: 5px;
  padding: 5px 13px;
  background: linear-gradient(#ffffff, #dfeaf5);
  color: #243f59;
  font-size: 12px;
}

.btn:hover:not(:disabled) {
  background: linear-gradient(#ffffff, #cbdfF2);
}

.btn.primary {
  border-color: #4e84b9;
  background: linear-gradient(#69a8e2, #2f73c6);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(#7db5e9, #2b69b6);
}

.btn.danger {
  border-color: #b57272;
  background: linear-gradient(#fbe3e3, #e9b7b7);
  color: #7c2828;
}

.btn.subtle {
  background: transparent;
  border-color: transparent;
  color: var(--accent-dark);
}

.form-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 9px 12px;
  align-items: center;
}

.form-grid label {
  color: #40556b;
  font-size: 12px;
}

.form-grid input[type="number"],
.form-grid select,
.form-grid input[type="text"] {
  height: 26px;
  padding: 2px 6px;
  border: 1px solid #9eb1c4;
  border-radius: 4px;
  background: #fff;
}

.form-grid input[type="color"] {
  width: 48px;
  height: 26px;
  padding: 1px;
  border: 1px solid #9eb1c4;
  border-radius: 4px;
  background: #fff;
}

.form-note {
  color: #66788b;
  font-size: 11px;
  line-height: 1.4;
}

.doc-layout {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 0;
  flex: 1 1 auto;
}

.doc-toc {
  overflow: auto;
  padding: 9px 8px;
  background: linear-gradient(#f2f7fc, #e3ecf5);
  border-right: 1px solid #b9c9d8;
}

.doc-section-title {
  margin: 8px 4px 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6a7f94;
  font-weight: 700;
}

.doc-toc button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 4px;
  padding: 4px 7px;
  background: transparent;
  text-align: left;
  color: #2b4055;
  font-size: 11.5px;
}

.doc-toc button:hover {
  background: rgba(45, 111, 206, 0.1);
}

.doc-toc button.active {
  background: linear-gradient(#5a98db, #2f73c6);
  color: #fff;
}

.doc-content {
  overflow: auto;
  padding: 16px 20px 28px;
  background: #fff;
  line-height: 1.48;
}

.doc-content h2 {
  margin: 0 0 12px;
  color: #12395e;
  font-size: 21px;
  border-bottom: 1px solid #d6e1ec;
  padding-bottom: 7px;
}

.doc-content h3 {
  margin: 22px 0 8px;
  color: #17466f;
  font-size: 16px;
}

.doc-content h4 {
  margin: 16px 0 6px;
  color: #1f5278;
  font-size: 13.5px;
}

.doc-content p {
  margin: 0 0 10px;
}

.doc-content ul,
.doc-content ol {
  margin: 6px 0 12px;
  padding-left: 22px;
}

.doc-content code {
  background: #edf3f9;
  border: 1px solid #dce6f0;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 14px;
  font-size: 11.5px;
}

.doc-table th,
.doc-table td {
  border: 1px solid #c8d6e4;
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
}

.doc-table th {
  background: #e6eff8;
  color: #234766;
}

.doc-table tr:nth-child(even) td {
  background: #f8fbfe;
}

.doc-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #edf4fa;
  border-top: 1px solid #c8d6e4;
}

.docs-empty {
  padding: 30px;
  text-align: center;
  color: #6a7e93;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 14px;
}

.dialog-error {
  margin-top: 10px;
  padding: 7px 9px;
  border: 1px solid #d9a3a3;
  border-radius: 5px;
  background: #fdecec;
  color: #8b2424;
  font-size: 11.5px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.score-card {
  padding: 10px;
  border: 1px solid #c4d3e2;
  border-radius: 7px;
  background: linear-gradient(#f9fcff, #e9f1f9);
  text-align: center;
}

.score-card strong {
  display: block;
  font-size: 22px;
  color: #1f5f9f;
}

.score-card span {
  font-size: 10px;
  color: #5e7287;
}

.score-total {
  margin: 12px 0;
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  color: #1d5c99;
}

.score-total small {
  font-size: 14px;
  color: #71859a;
}

.bilan-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 5px;
  background: #f1f6fb;
  margin-bottom: 6px;
}

.bilan-row .status {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 3px;
  border-radius: 50%;
  background: #aab8c6;
}

.bilan-row.ok .status {
  background: #3ca553;
}

.bilan-row.fail .status {
  background: #cf4a4a;
}

.bilan-row .name {
  font-weight: 600;
}

.bilan-row .detail {
  color: #5e7084;
  font-size: 11px;
}

.project-list {
  display: grid;
  gap: 5px;
}

.project-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #c8d5e2;
  border-radius: 5px;
  background: #f8fbfe;
}

.project-row.active {
  background: #e6f1fc;
  border-color: #8fb8dc;
}

.project-row .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.project-row .name {
  flex: 1 1 auto;
  font-weight: 600;
}

.project-row.hidden-tab .name {
  color: #9aa9b8;
  text-decoration: line-through;
}

.help-hint {
  color: #6b7d90;
  font-size: 11px;
  line-height: 1.45;
}

.level-list {
  display: grid;
  gap: 4px;
  max-height: 240px;
  overflow: auto;
  margin: 8px 0;
}

.level-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: 1px solid #ccd8e4;
  border-radius: 5px;
  background: #fbfdff;
  cursor: pointer;
}

.level-option.active {
  background: #e5f0fc;
  border-color: #8fb8dc;
}

.level-option .num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #dceaf8;
  color: #23537f;
  font-weight: 700;
}

.level-option .desc {
  font-size: 10.5px;
  color: #62758a;
}

.level-details {
  margin-top: 10px;
  padding: 9px 11px;
  border: 1px solid #cddae6;
  border-radius: 6px;
  background: #f7fafd;
  font-size: 11px;
  color: #435a70;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 46px;
  z-index: 2000;
  transform: translateX(-50%);
  max-width: min(520px, 86vw);
  padding: 8px 14px;
  border: 1px solid #7c93aa;
  border-radius: 20px;
  background: rgba(24, 40, 57, 0.94);
  color: #f0f7ff;
  font-size: 11.5px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  animation: toast-in 0.18s ease-out;
  pointer-events: none;
}

.toast.error {
  background: rgba(122, 35, 35, 0.96);
  border-color: #a55a5a;
}

.toast.success {
  background: rgba(30, 100, 47, 0.96);
  border-color: #5da36e;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.about-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.about-logo {
  flex: 0 0 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: radial-gradient(circle at 40% 30%, #f8fcff, #cfe3f5);
  border: 1px solid #9eb8d0;
}

.about-logo svg {
  width: 78px;
  height: 78px;
}

.about-text h2 {
  margin: 0 0 4px;
  color: #173f64;
}

.about-text p {
  margin: 0 0 7px;
  color: #4d6378;
}

.about-text .version {
  font-size: 11px;
  color: #7a8da0;
}

@media (max-width: 1250px) {
  .workspace {
    grid-template-columns: 178px minmax(380px, 1.1fr) minmax(315px, 0.9fr);
  }
  .tool-grid {
    gap: 5px;
    padding: 8px 7px 5px;
  }
  .tool-btn {
    min-height: 54px;
  }
  .tool-btn .tool-label {
    font-size: 8.5px;
  }
}

@media (max-width: 1050px) {
  body {
    overflow: auto;
  }
  #app {
    min-height: 100vh;
    height: auto;
  }
  .workspace {
    grid-template-columns: 178px 1fr;
    grid-template-rows: minmax(430px, 1fr) minmax(390px, 0.9fr);
    height: auto;
    min-height: 0;
    flex: 1 1 auto;
  }
  .palette {
    grid-row: 1 / span 2;
  }
  .program-window,
  .execution-window {
    min-height: 0;
  }
  .menubar {
    flex-wrap: wrap;
    height: auto;
    min-height: 43px;
    padding-top: 4px;
    padding-bottom: 4px;
  }
  .menu-bar {
    flex-wrap: wrap;
    height: auto;
  }
  .dropbtn,
  .menu-title {
    height: 30px;
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(460px, 70vh) minmax(380px, 60vh);
    padding: 7px;
  }
  .palette {
    grid-row: auto;
  }
  .tool-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .tool-btn {
    min-height: 50px;
  }
  .brand {
    min-width: 0;
  }
  .brand-name {
    font-size: 13px;
  }
  .menubar-right {
    width: 100%;
    justify-content: flex-end;
    padding-bottom: 2px;
  }
  .doc-layout {
    grid-template-columns: 1fr;
  }
  .doc-toc {
    max-height: 170px;
    border-right: 0;
    border-bottom: 1px solid #b9c9d8;
  }
  .score-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  body * {
    visibility: hidden;
  }
  .modal-backdrop,
  .modal-backdrop * {
    visibility: visible;
  }
  .modal-backdrop {
    position: static;
    background: #fff;
    padding: 0;
  }
  .modal {
    box-shadow: none;
    border: 0;
    width: 100%;
    max-height: none;
  }
  .doc-toc,
  .modal-footer,
  .modal-header,
  .doc-nav {
    display: none;
  }
  .doc-content {
    overflow: visible;
    padding: 0;
  }
}

.flow-surface.grid-grey {
  background-image:
    linear-gradient(to right, rgba(90, 106, 122, 0.18) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, rgba(90, 106, 122, 0.18) 0.5px, transparent 0.5px),
    linear-gradient(to right, rgba(90, 106, 122, 0.06) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, rgba(90, 106, 122, 0.06) 0.5px, transparent 0.5px);
}

.flow-surface.grid-none {
  background-image: none;
}

.workspace.no-palette {
  grid-template-columns: minmax(420px, 1.18fr) minmax(350px, 0.92fr);
}

.workspace.no-exec {
  grid-template-columns: 196px minmax(420px, 1fr);
}

.workspace.no-palette.no-exec {
  grid-template-columns: minmax(420px, 1fr);
}

.modal.docs-modal .modal-body,
.modal.terrain-modal .modal-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal.docs-modal .doc-layout {
  flex: 1 1 auto;
  min-height: 0;
}

.modal.terrain-modal .modal-body {
  flex-direction: row;
}

.terrain-editor-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 180px 1fr;
}

.terrain-editor-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  background: linear-gradient(#f3f8fd, #e3ecf5);
  border-right: 1px solid #b9c9d8;
}

.terrain-tool {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 9px;
  border: 1px solid #b7c6d5;
  border-radius: 6px;
  background: linear-gradient(#ffffff, #edf3f9);
  text-align: left;
}

.terrain-tool span {
  font-weight: 700;
  font-size: 11.5px;
  color: #29465f;
}

.terrain-tool small {
  font-size: 9.5px;
  color: #75879a;
}

.terrain-tool:hover {
  border-color: #7ea4c8;
}

.terrain-tool.active {
  border-color: #2d6fce;
  background: linear-gradient(#e8f2ff, #c4dcf4);
  box-shadow: 0 0 0 2px rgba(45, 111, 206, 0.16);
}

.terrain-robot-actions {
  display: flex;
  gap: 6px;
}

.terrain-robot-actions .btn {
  flex: 1 1 auto;
}

.terrain-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #eaf0f6;
}

.terrain-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.variables-body {
  max-height: 62vh;
  overflow: auto;
}

@media (max-width: 1050px) {
  .workspace.no-palette {
    grid-template-columns: 1fr;
  }
  .workspace.no-exec {
    grid-template-columns: 178px 1fr;
  }
  .workspace.no-palette.no-exec {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace.no-palette,
  .workspace.no-exec,
  .workspace.no-palette.no-exec {
    grid-template-columns: 1fr;
  }
  .terrain-editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .terrain-editor-tools {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid #b9c9d8;
  }
  .terrain-tool {
    flex: 1 1 120px;
  }
}


.doc-figure {
  margin: 14px 0 18px;
  padding: 8px;
  border: 1px solid #d3e0ec;
  border-radius: 8px;
  background: #f7fafd;
  text-align: center;
}

.doc-figure img {
  display: block;
  width: 100%;
  max-width: 760px;
  height: auto;
  margin: 0 auto;
  border-radius: 4px;
}

.doc-figure figcaption {
  margin-top: 7px;
  color: #62758a;
  font-size: 11px;
  line-height: 1.35;
}
