html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1e1e1e;
}

#canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: grab;
}

#canvas.panning {
  cursor: grabbing;
}

#topbar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
  background: rgba(25, 25, 28, 0.97);
  border-bottom: 1px solid #3a3a3a;
  user-select: none;
  z-index: 900;
}

.menu-tab {
  padding: 4px 12px;
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.menu-tab:hover {
  background: #333;
}

#project-name {
  font: bold 12px/1.4 sans-serif;
  color: #777;
}

#file-menu {
  position: fixed;
  left: 8px;
  top: 36px;
  z-index: 1000;
  min-width: 220px;
  padding: 4px;
  background: rgba(35, 35, 40, 0.97);
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  user-select: none;
}

#file-menu.hidden {
  display: none;
}

.dialog {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 1002;
  min-width: 280px;
  padding: 14px;
  background: rgba(35, 35, 40, 0.98);
  border: 1px solid #4a4a4a;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  user-select: none;
}

.dialog.hidden {
  display: none;
}

.dialog-title {
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  margin-bottom: 10px;
}

#save-name {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 4px 6px;
  font: bold 13px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #5590e0;
  border-radius: 4px;
  outline: none;
}

#project-list {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.project-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.project-row:hover {
  background: #3a3a4a;
}

.project-row .p-date {
  margin-left: auto;
  font-size: 11px;
  color: #777;
  font-weight: normal;
}

.project-row .p-del {
  color: #c07070;
  font-size: 11px;
}

.project-row .p-del:hover {
  color: #ff9090;
}

.project-empty {
  color: #666;
  font: italic 12px/1.4 sans-serif;
  padding: 4px;
}

#left-panel {
  position: fixed;
  left: 10px;
  top: 44px;
  width: 170px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 54px);
}

#selector,
#tree-panel {
  padding: 8px;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  user-select: none;
}

#tree-panel {
  overflow-y: auto;
  min-height: 40px;
}

#tree {
  font: bold 13px/1.5 sans-serif;
  color: #ccc;
}

.tree-empty {
  color: #666;
  font-style: italic;
  font-size: 12px;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.tree-row:hover {
  background: #333;
}

.tree-row.selected {
  background: #2e4a66;
  color: #cfe6ff;
  outline: 1px solid #7fb8e8;
  outline-offset: -1px;
}

.tree-toggle {
  width: 14px;
  flex: none;
  color: #888;
  font-size: 10px;
  text-align: center;
}

.tree-toggle:hover {
  color: #fff;
}

.tree-label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.tree-del {
  flex: none;
  width: 16px;
  text-align: center;
  color: #c07070;
  font-size: 11px;
  visibility: hidden;
}

.tree-row:hover .tree-del {
  visibility: visible;
}

.tree-del:hover {
  color: #ff9090;
}

.tree-rename {
  flex: 1;
  min-width: 0;
  font: bold 13px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #5590e0;
  border-radius: 3px;
  padding: 0 4px;
  outline: none;
}

.selector-title {
  font: bold 12px/1.4 sans-serif;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.selector-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  cursor: grab;
}

.selector-item:hover {
  background: #333;
  border-color: #4a4a4a;
}

.selector-item:active {
  cursor: grabbing;
}

/* Выбранный инструмент палитры (режим клик-размещения) */
.selector-item.active {
  background: #2e4a66;
  border-color: #7fb8e8;
  color: #cfe6ff;
  box-shadow: 0 0 0 1px #7fb8e8 inset;
}

.item-icon {
  font-size: 16px;
}

/* Скелетная (контурная) иконка изображения */
.icon-image {
  color: #8ab0d8;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.icon-image svg {
  display: block;
}

/* Иконка текстового объекта — стилизованная буква T с засечками */
.icon-text {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: bold;
  font-size: 15px;
  color: #8ab0d8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  width: 16px;
  display: inline-block;
  text-align: center;
  flex: none;
}

/* Иконка точки в древе / палитре — цветной кружок */
.icon-point {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.palette-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  background: #f0b429;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

/* Свотч полотна в селекторе */
.palette-square {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  display: inline-block;
  background: #4671b0;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

/* Иконка полотна в древе — залитый квадрат цвета полотна */
.icon-panel {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
  flex: none;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

/* Иконка линии в древе — короткий отрезок */
.icon-line {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
  flex: none;
}

/* Панель свойств выделенной точки/линии */
#props-panel {
  position: fixed;
  right: 222px;
  top: 44px;
  z-index: 950;
  width: 190px;
  padding: 10px;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  user-select: none;
}

/* Панель переменных (правый край) */
#vars-panel {
  position: fixed;
  right: 10px;
  top: 44px;
  z-index: 950;
  width: 200px;
  max-height: 42vh;
  overflow-y: auto;
  padding: 10px;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  user-select: none;
}

#vars-panel.collapsed { display: none; }

.vars-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#vars-toggle {
  flex: none;
  width: 20px;
  height: 20px;
  padding: 0;
  margin-bottom: 8px;
  color: #999;
  background: transparent;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
}
#vars-toggle:hover { color: #eee; border-color: #7fb8e8; }

#vars-show {
  position: fixed;
  right: 10px;
  top: 44px;
  z-index: 951;
  padding: 6px 10px;
  font: bold 12px/1 sans-serif;
  color: #cfe6ff;
  background: rgba(46, 74, 102, 0.95);
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  cursor: pointer;
}
#vars-show:hover { border-color: #7fb8e8; }
#vars-show.hidden { display: none; }

/* Панель пресетов (правый край, снизу) */
#presets-panel {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 950;
  width: 200px;
  max-height: 42vh;
  overflow-y: auto;
  padding: 10px;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  user-select: none;
}

.preset-item {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
  padding: 5px 6px;
  background: #1e1e1e;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}
.preset-item:hover { border-color: #7fb8e8; background: #24303c; }
.preset-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: bold 12px/1.3 sans-serif;
  color: #ddd;
}
.preset-del {
  flex: none;
  width: 18px;
  height: 20px;
  padding: 0;
  color: #c07070;
  background: transparent;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}
.preset-del:hover { border-color: #c07070; color: #e08080; }

.icon-varstore {
  width: 14px;
  display: inline-block;
  text-align: center;
  flex: none;
  font-size: 12px;
}

.var-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
}

.var-name,
.var-value {
  min-width: 0;
  font: bold 12px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  padding: 3px 5px;
  outline: none;
}

.var-name { flex: 0 0 70px; color: #cfe6ff; }
.var-value { flex: 1; }
.var-name:focus,
.var-value:focus { border-color: #5590e0; }

.var-del {
  flex: none;
  width: 20px;
  height: 22px;
  padding: 0;
  color: #c07070;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}
.var-del:hover { border-color: #c07070; color: #e08080; }

#vars-add {
  width: 100%;
  margin-top: 2px;
  padding: 4px 0;
  font: bold 12px/1.2 sans-serif;
  color: #cfe6ff;
  background: #2e4a66;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}
#vars-add:hover { border-color: #7fb8e8; }

.vars-empty {
  color: #666;
  font: 12px/1.4 sans-serif;
  margin-bottom: 6px;
}

.vars-hint {
  margin-top: 8px;
  color: #777;
  font: 11px/1.4 sans-serif;
}

#props-panel.hidden {
  display: none;
}

.props-title {
  font: bold 12px/1.4 sans-serif;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.prop-label {
  flex: none;
  width: 58px;
  font: bold 12px/1.4 sans-serif;
  color: #aaa;
}

.prop-input {
  flex: 1;
  min-width: 0;
  font: bold 12px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  padding: 3px 5px;
  outline: none;
}

.prop-input:focus {
  border-color: #5590e0;
}

.prop-textarea {
  resize: vertical;
  min-height: 44px;
  line-height: 1.35;
  white-space: pre;
  overflow: auto;
}

.prop-color {
  flex: 1;
  height: 24px;
  padding: 0;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  background: #1a1a1a;
  cursor: pointer;
}

.prop-range {
  flex: 1;
  min-width: 0;
  accent-color: #5590e0;
}

.prop-btn {
  width: 100%;
  margin-top: 2px;
  padding: 5px 8px;
  font: bold 12px/1.4 sans-serif;
  color: #ddd;
  background: #2a2a2a;
  border: 1px solid #4a4a4a;
  border-radius: 4px;
  cursor: pointer;
}

.prop-btn:hover {
  background: #333;
  border-color: #5590e0;
}

.prop-hint {
  margin-top: 8px;
  font: 11px/1.4 sans-serif;
  color: #777;
}

#reset-view {
  position: fixed;
  right: 10px;
  bottom: 10px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
  color: #ddd;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  cursor: pointer;
}

#reset-view:hover {
  background: #333;
  border-color: #4a4a4a;
}

#anim-toggle {
  position: fixed;
  right: 10px;
  bottom: 52px;
  width: 36px;
  height: 36px;
  font-size: 17px;
  line-height: 1;
  color: #ddd;
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  cursor: pointer;
}

#anim-toggle:hover {
  background: #333;
  border-color: #4a4a4a;
}

/* выключенные анимации — зачёркнутая иконка */
#anim-toggle.off {
  color: #666;
}

#anim-toggle.off::after {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  top: 50%;
  border-top: 2px solid #c07070;
  transform: rotate(-45deg);
}

#context-menu {
  position: fixed;
  z-index: 1000; /* над всеми объектами */
  min-width: 180px;
  padding: 4px;
  background: rgba(35, 35, 40, 0.97);
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  user-select: none;
}

#context-menu.hidden {
  display: none;
}

.menu-item {
  padding: 6px 10px;
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  border-radius: 4px;
  cursor: pointer;
}

.menu-item:hover {
  background: #3a3a4a;
}

.menu-sep {
  height: 1px;
  background: #4a4a4a;
  margin: 4px 6px;
}

.menu-item[data-action="delete"] {
  color: #c07070;
}

#confirm-box {
  position: fixed;
  z-index: 1001;
  min-width: 200px;
  padding: 12px;
  background: rgba(35, 35, 40, 0.97);
  border: 1px solid #4a4a4a;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  user-select: none;
}

#confirm-box.hidden {
  display: none;
}

#confirm-text {
  font: bold 13px/1.4 sans-serif;
  color: #ddd;
  margin-bottom: 10px;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-actions button {
  padding: 4px 12px;
  font: bold 12px/1.4 sans-serif;
  border-radius: 4px;
  border: 1px solid #4a4a4a;
  cursor: pointer;
  background: #2a2a2a;
  color: #ddd;
}

#confirm-yes {
  background: #6e3030;
  border-color: #8a4040;
  color: #f0c0c0;
}

#confirm-yes:hover {
  background: #8a3838;
}

#confirm-no:hover {
  background: #333;
}

.text-edit {
  position: fixed;
  z-index: 1000;
  color: #eee;
  background: rgba(26, 26, 26, 0.95);
  border: 1px solid #5590e0;
  border-radius: 3px;
  padding: 2px 4px;
  outline: none;
  resize: none;
  white-space: pre;
}

.header-rename {
  position: fixed;
  z-index: 1000;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #5590e0;
  border-radius: 3px;
  padding: 0 4px;
  outline: none;
}

#hud {
  position: fixed;
  left: 10px;
  bottom: 10px;
  padding: 4px 10px;
  font: bold 12px/1.4 monospace;
  color: #aaa;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  pointer-events: none;
  user-select: none;
}

.prop-check {
  width: 16px;
  height: 16px;
  margin-right: auto;
  accent-color: #5590e0;
  cursor: pointer;
}

.prop-select {
  flex: 1;
  min-width: 0;
  font: bold 12px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  padding: 3px 4px;
  outline: none;
  cursor: pointer;
}

.prop-select:focus {
  border-color: #5590e0;
}

/* Радиокнопки типа стрелки линии */
.arrow-group {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.arrow-opt {
  flex: 1;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #bbb;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}

.arrow-opt:hover {
  border-color: #5590e0;
  color: #eee;
}

.arrow-opt.active {
  background: #2e4a66;
  border-color: #7fb8e8;
  color: #cfe6ff;
}

.arrow-opt svg {
  display: block;
}

/* Компас 3×3 для выбора положения подписи точки */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.pos-opt {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font: 14px/1 sans-serif;
  color: #bbb;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  cursor: pointer;
}

.pos-opt:hover {
  border-color: #5590e0;
  color: #eee;
}

.pos-opt.active {
  background: #2e4a66;
  border-color: #7fb8e8;
  color: #cfe6ff;
}

/* Числовое поле рядом с ползунком */
.prop-numrange {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.prop-numrange .prop-range {
  flex: 1;
  min-width: 0;
}

.prop-num {
  width: 48px;
  flex: none;
  font: bold 12px/1.4 sans-serif;
  color: #eee;
  background: #1a1a1a;
  border: 1px solid #4a4a4a;
  border-radius: 3px;
  padding: 2px 4px;
  outline: none;
}

.prop-num:focus {
  border-color: #5590e0;
}

/* Подзаголовок раздела свойств */
.prop-subhead {
  font: bold 11px/1.4 sans-serif;
  color: #7fb8e8;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 2px 0 7px;
  padding-bottom: 3px;
  border-bottom: 1px solid #3a3a3a;
}

/* Слои в дереве */
.tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tree-head .selector-title {
  margin-bottom: 0;
}

#add-layer {
  font: bold 11px/1 sans-serif;
  color: #cfe6ff;
  background: #2e4a66;
  border: 1px solid #4a6a86;
  border-radius: 4px;
  padding: 3px 7px;
  cursor: pointer;
}

#add-layer:hover {
  background: #365a7e;
  border-color: #7fb8e8;
}

.tree-layer {
  font-weight: bold;
  color: #cfe0ee;
}

.tree-layer.active-layer {
  background: #26333f;
  outline: 1px solid #4a6a86;
  outline-offset: -1px;
}

.layer-eye {
  flex: none;
  width: 16px;
  text-align: center;
  color: #7fb8e8;
  cursor: pointer;
  font-size: 12px;
}

.layer-eye.off {
  color: #666;
}

.layer-eye:hover {
  color: #a9d3f5;
}

.tree-row.primary {
  box-shadow: inset 2px 0 0 #7fb8e8;
}

/* Индикатор места вставки при перетаскивании в дереве */
.tree-row.drop-into {
  background: #2e4a66;
  box-shadow: inset 0 0 0 1px #7fb8e8;
}

.tree-row.drop-before {
  box-shadow: inset 0 2px 0 0 #7fb8e8;
}

.tree-row.drop-after {
  box-shadow: inset 0 -2px 0 0 #7fb8e8;
}
