/* ============================================================
   Палитра: Catppuccin Mocha
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  cursor: default !important;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: "Comic Sans MS", cursive;
  font-size: 15px;
}

#canvas {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: #1e1e2e;
  background-image:
    linear-gradient(rgba(137, 180, 250, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(137, 180, 250, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(137, 180, 250, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(137, 180, 250, 0.09) 1px, transparent 1px);
  background-size: 20px 20px, 20px 20px, 100px 100px, 100px 100px;
  background-position: 0px 0px;
  touch-action: none;
}

#svg-layer {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 10; pointer-events: all;
  touch-action: none;
}

body.pan-mode * { cursor: grab !important; }
body.pan-mode.is-panning * { cursor: grabbing !important; }
body.brush-mode * { cursor: crosshair !important; }
body.brush-mode.pan-mode * { cursor: crosshair !important; }

.diagram-text {
  fill: #cdd6f4;
  font-family: "Comic Sans MS", cursive;
  font-size: 15px;
  pointer-events: none;
  dominant-baseline: central;
  user-select: none;
  -webkit-user-select: none;
}
.text-element {
  pointer-events: stroke;
  cursor: default;
}
.text-element.selected { fill: #f9e2af; }

.arrow-line { stroke: #cdd6f4; stroke-width: 2.5; pointer-events: none; }
.arrow-line.selected { stroke: #f9e2af; stroke-dasharray: 5,4; }
.arrow-hit {
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: default !important;
}

.diagram-text.selected { fill: #f9e2af; }

/* --- Фон подписи под текстом (обычный) --- */
.text-bg-rect {
  fill: #1e1e2e; rx: 4; ry: 4;
  pointer-events: none; display: none;
}
.text-bg-rect.selected {
  display: block;
  stroke: #f9e2af;
  stroke-width: 1;
  stroke-dasharray: 4,4;
}
.arrow-text-bg {
  fill: #1e1e2e; rx: 4; ry: 4;
  pointer-events: none;
}

/* --- Стикер: dashed рамка + полупрозрачный голубой фон --- */
.text-bg-rect.sticker {
  display: block;
  fill: rgba(137, 180, 250, 0.12);
  stroke: #89b4fa;
  stroke-width: 1;
  stroke-dasharray: 4,4;
  rx: 8; ry: 8;
}
.text-bg-rect.sticker.selected {
  stroke: #f9e2af;
  stroke-width: 1.5;
}

#text-input {
  position: fixed; z-index: 100; display: none;
  background: transparent; color: #cdd6f4; border: none;
  padding: 0; margin: 0;
  font-size: 15px; font-family: "Comic Sans MS", cursive;
  outline: none; box-shadow: none;
  white-space: pre; overflow: hidden;
  line-height: 18px;
  transform: translate(-50%, -50%);
  cursor: text !important; user-select: text !important;
  -webkit-user-select: text !important;
  resize: none; text-align: center;
  min-width: 0; min-height: 0; width: auto; height: auto;
}

#top-buttons {
  position: fixed;
  top: 14px; right: 14px;
  display: flex;
  flex-direction: row;
  gap: 8px;
  z-index: 200;
}

.top-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid #89b4fa;
  background: #181825;
  color: #89b4fa;
  font-family: "Comic Sans MS", cursive;
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  padding: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.top-btn:hover {
  background: #262637;
  border-color: #74c7ec;
  color: #74c7ec;
}
.top-btn.active {
  background: #313244;
  border-color: #74c7ec;
  color: #74c7ec;
}
.top-btn svg { display: block; }

#help-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 300;
  display: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#help-backdrop.open { display: block; }

#help-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  height: 90vh;
  max-width: 1500px;
  background: #181825;
  border: 2px solid #313244;
  border-radius: 14px;
  padding: 36px 44px 32px 44px;
  z-index: 301;
  overflow-y: auto;
  font-family: "Comic Sans MS", cursive;
  font-size: 14px;
  color: #cdd6f4;
  line-height: 1.55;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
  display: none;
  box-sizing: border-box;
}
#help-panel.open { display: block; }
#help-panel::-webkit-scrollbar { width: 10px; }
#help-panel::-webkit-scrollbar-track { background: transparent; }
#help-panel::-webkit-scrollbar-thumb {
  background: #313244; border-radius: 5px;
}
#help-panel::-webkit-scrollbar-thumb:hover { background: #45475a; }

#help-panel h2 {
  margin: 0 0 24px 0;
  font-size: 22px;
  color: #89b4fa;
  font-weight: normal;
  letter-spacing: 0.3px;
}

#help-content {
  column-count: 3;
  column-gap: 44px;
}
@media (max-width: 1100px) { #help-content { column-count: 2; } }
@media (max-width: 720px)  { #help-content { column-count: 1; } }

#help-content section {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 22px;
}

#help-panel h3 {
  margin: 0 0 8px 0;
  font-size: 12px;
  color: #6c7086;
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid #313244;
  padding-bottom: 6px;
}

#help-panel .item { margin: 6px 0; }

#help-panel .key {
  display: inline-block;
  padding: 1px 7px;
  border: 1.5px solid #45475a;
  border-radius: 4px;
  background: rgba(137, 180, 250, 0.06);
  color: #89b4fa;
  font-family: "Comic Sans MS", cursive;
  font-size: 12px;
  margin-right: 4px;
  white-space: nowrap;
}

#help-panel .desc { color: #a6adc8; }

#help-close {
  position: absolute;
  top: 18px; right: 18px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 2px solid #89b4fa;
  background: #181825;
  color: #89b4fa;
  font-family: "Comic Sans MS", cursive;
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer !important;
  padding: 0 0 2px 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  z-index: 2;
}
#help-close:hover {
  background: #313244;
  border-color: #74c7ec;
  color: #74c7ec;
}

#file-input { display: none; }

.selection-rect {
  fill: rgba(137, 180, 250, 0.12);
  stroke: #89b4fa;
  stroke-width: 1;
  stroke-dasharray: 4,4;
  pointer-events: none;
}