* { box-sizing: border-box; }
body { margin: 0; background: #0f1115; color: #e8e8e8; display: flex; height: 100vh; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
.panel { width: 380px; padding: 20px; background: #171a21; overflow-y: auto; height: 100vh; border-right: 1px solid #2a2f3a; flex-shrink: 0; position: sticky; top: 0; }
h1 { font-size: 18px; margin: 0 0 16px; }
label { display: block; font-size: 12px; color: #9aa4b2; margin: 14px 0 6px; font-weight: bold;}
input, select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #2a2f3a;
  background: #0f1115;
  color: #e8e8e8;
  font-size: 14px;
  outline: none;
}
select { cursor: pointer; }

/* Лента с цветом слова (color picker) на мобильных слишком широкая и белая.
 * На телефоне делаем полупрозрачную, узкую, как кнопка.
 * На компьютере оставляем как есть — там она вписывается в панель.
 */
#qbWordColor {
  width: 56px !important;
  height: 42px !important;
  padding: 4px !important;
  background: rgba(42, 47, 58, 0.85) !important;
  border: 1px solid rgba(122, 162, 255, 0.45) !important;
  cursor: pointer;
}

@media (min-width: 821px) {
  #qbWordColor {
    width: 100% !important;
    height: auto !important;
    padding: 10px !important;
    background: #0f1115 !important;
    border: 1px solid #2a2f3a !important;
  }
}
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > button { flex: 1 1 30%; }
button { cursor: pointer; border: none; border-radius: 8px; padding: 10px; font-size: 13px; font-weight: 600; transition: 0.2s; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
.preset { background: #2a2f3a; color: #e8e8e8; }
.preset.active { background: #3d7eff; }
.primary { background: #3d7eff; color: #fff; width: 100%; margin-top: 15px; padding: 14px; font-size: 15px;}
.primary:hover { background: #2b66d9; }
.danger { background: rgba(255, 77, 77, 0.1); color: #ff4d4d; border: 1px solid #ff4d4d; width: 100%; margin-top: 10px; padding: 12px;}
.danger:hover { background: #ff4d4d; color: #fff; }

input[type=range] { padding: 0; cursor: pointer; width: 100%; }
input[type=color] { height: 40px; padding: 0; cursor: pointer; border-radius: 6px; border: 1px solid #2a2f3a; background: #0f1115; overflow: hidden; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; background: #0f1115; padding: 10px; border-radius: 8px; border: 1px solid #2a2f3a; align-items: center; }
.toolbar button { flex: none; min-width: 32px; height: 32px; padding: 0 6px; background: #2a2f3a; color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; border-radius: 6px; }
.toolbar button:hover:not(:disabled) { background: #3d7eff; }
.toolbar input[type=color] { width: 32px; height: 32px; padding: 0; border: none; border-radius: 6px; cursor: pointer; overflow: hidden; }
.toolbar .toolbar-divider { width: 1px; height: 24px; background: #4a5568; margin: 0 2px; }
.emoji-section-title { font-size: 11px; color: #9aa4b2; margin: 10px 0 4px; font-weight: bold; }
.emoji-bar { display: flex; flex-wrap: wrap; gap: 2px; }
.emoji-bar span { cursor: pointer; font-size: 20px; padding: 3px; border-radius: 6px; user-select: none; }
.emoji-bar span:hover { background: #2a2f3a; }
.emoji-wrap { max-height: 220px; overflow-y: auto; background: #0f1115; border: 1px solid #2a2f3a; border-radius: 8px; padding: 8px; margin-top: 8px; }
.ratio-box { margin-top: 20px; padding: 14px; border-radius: 10px; border: 2px solid #4ade80; background: rgba(74, 222, 128, 0.08); transition: 0.3s; }
.ratio-box.warn { border-color: #fbbf24; background: rgba(251, 191, 36, 0.08); }
.ratio-box.danger { border-color: #ff4d4d; background: rgba(255, 77, 77, 0.1); }
.ratio-title { font-size: 13px; font-weight: bold; margin-bottom: 8px; }
.ratio-title.ok { color: #4ade80; }
.ratio-title.warn { color: #fbbf24; }
.ratio-title.danger { color: #ff4d4d; }
.ratio-info { font-size: 12px; color: #9aa4b2; }
.ratio-bar-track { height: 8px; background: #2a2f3a; border-radius: 4px; margin: 8px 0; overflow: hidden; }
.ratio-bar-fill { height: 100%; width: 0%; border-radius: 4px; transition: width 0.3s, background 0.3s; }
.stats-box { background: #0f1115; border: 1px solid #2a2f3a; padding: 10px; border-radius: 8px; margin-top: 12px; font-size: 12px; color: #9aa4b2; }
.stats-row { display: flex; justify-content: space-between; }

/* ===== ХОЛСТ ===== */
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 30px; overflow: hidden; background-color: #748eaa; transition: background 0.3s; cursor: grab; position: relative; }
.stage.panning { cursor: grabbing; }
#zoom-wrapper { transition: transform 0.15s ease; transform-origin: top center; -webkit-user-select: text; user-select: text; }
#zoom-wrapper.dragging { transition: none; }

#export-node { --bg-color: #ffffff; --text-color: #000000; background: var(--bg-color); color: var(--text-color); padding: 32px 40px; border-radius: 24px 24px 24px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.15); width: 800px; position: relative; margin: auto; transition: width 0.3s, border-radius 0.3s, background 0.3s, color 0.3s; -webkit-user-select: text; user-select: text; }
#export-node::before { content: ''; position: absolute; bottom: 0; left: -16px; width: 16px; height: 32px; background: radial-gradient(circle at 0 0, transparent 16px, var(--bg-color) 16px); }
#export-node.no-tail::before { display: none; }

#editor {
outline: none; font-size: 32px; line-height: 1.2; white-space: pre-wrap;
word-break: normal; overflow-wrap: break-word; -webkit-hyphens: none; hyphens: none;
min-height: 100px; text-align: justify; text-align-last: left; transition: font-size 0.2s; display: flow-root;
cursor: text; -webkit-user-select: text; user-select: text; -webkit-touch-callout: default;
caret-color: #000000;
font-weight: 400;
-webkit-font-smoothing: antialiased;
}
#editor, #editor * { caret-color: #000000 !important; }
#editor[placeholder]:empty:before { content: attr(placeholder); opacity: 0.5; }
#editor code { background: rgba(128,128,128,0.2); padding: 4px 8px; border-radius: 6px; font-family: monospace; }
#editor a { color: #3d7eff; text-decoration: underline; cursor: pointer; }
.img-box { position: relative; float: left; margin: 8px 20px 8px 0; width: 50%; max-width: 95%; cursor: grab; user-select: none; -webkit-user-select: none; border-radius: 12px; }
.img-box.align-right { float: right; margin: 8px 0 8px 20px; }
.img-box.align-center { float: none; display: block; margin: 10px auto; clear: both; }
.img-spacer-left { float: left; height: 10px; width: var(--side-space, 0px); }
.img-spacer-right { float: right; height: 10px; width: var(--side-space, 0px); }
.img-box:active { cursor: grabbing; }
.img-box img { display: block; width: 100%; border-radius: 12px; pointer-events: none; }
.img-box.selected { outline: 3px solid #3d7eff; outline-offset: 3px; }
.img-resizer { position: absolute; right: 0; bottom: 0; width: 28px; height: 28px; cursor: nwse-resize; z-index: 10; display: none; }
.img-resizer::after { content: ''; position: absolute; right: 4px; bottom: 4px; width: 14px; height: 14px; border-right: 3px solid #fff; border-bottom: 3px solid #fff; border-radius: 2px; filter: drop-shadow(0 0 3px rgba(0,0,0,0.8)); }
.img-box.selected .img-resizer { display: block; }

/* ===== ЭТАП 1: улучшенные картинки ===== */
.img-box { transition: box-shadow .2s, border-radius .2s; }
.img-box img { transition: border-radius .2s, box-shadow .2s; }
.img-box { --img-radius: 12px; --img-border: 0px; --img-border-color: #000000; }
.img-box img { border-radius: var(--img-radius); box-shadow: 0 0 0 var(--img-border) var(--img-border-color); }
.img-box .img-rotor { display: block; transition: transform .12s linear; transform: rotate(var(--img-rot, 0deg)); transform-origin: center; }
.img-box .img-rotor img { border-radius: var(--img-radius); box-shadow: 0 0 0 var(--img-border) var(--img-border-color) !important; }

/* ===== ЭТАП 2: ТЕКСТОВЫЕ ПЛАШКИ (ТЕКСТ-БЛОКИ) ===== */
.text-box {
  position: absolute; left: 40px; top: 40px;
  min-width: 60px; max-width: 90%;
  z-index: 20;
  box-sizing: border-box;
  user-select: none; -webkit-user-select: none;
}
.text-box.selected { outline: 3px solid #10b981; outline-offset: 4px; border-radius: 12px; }

.text-box .tb-content {
  padding: 10px 14px;
  background: rgba(0,0,0,0.55); color: #ffffff;
  border-radius: 10px; font-size: 24px; line-height: 1.25;
  text-align: center;
  word-break: break-word; overflow-wrap: break-word;
  -webkit-user-select: text; user-select: text;
  outline: none; cursor: text;
  min-height: 1.25em;
}
.text-box .tb-content:empty:before {
  content: attr(data-ph); opacity: 0.6; font-style: italic;
}
  /* Режим ЛЕНТА: фон обтекает строки по ширине букв */
.text-box.mode-ribbon .tb-content {
  background: transparent !important;
  padding: 0;
}
.text-box.mode-ribbon .tb-content .tb-ribbon {
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  padding: var(--ribbon-pad-v, 0.25em) var(--ribbon-pad-h, 0.3em);
  border-radius: var(--ribbon-radius, 6px);
  background: var(--ribbon-bg, rgba(0,0,0,0.85));
  line-height: 1.0;
}
  /* ЭТАП 3: картинка внутри плашки */
.text-box .tb-content img.tb-img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 4px auto;
  border-radius: 6px;
  pointer-events: none;
  -webkit-user-select: none; user-select: none;
}

.text-box .tb-drag-frame {
  position: absolute; inset: -3px; z-index: 2;
  display: none; pointer-events: none;
}
.text-box.selected .tb-drag-frame { display: block; }
.text-box .tb-edge { position: absolute; pointer-events: auto; cursor: move; touch-action: none; }
.text-box .tb-edge.top    { top: -3px; left: -3px; right: -3px; height: 12px; }
.text-box .tb-edge.bottom { bottom: -3px; left: -3px; right: -3px; height: 12px; }
.text-box .tb-edge.left   { left: -3px; top: -3px; bottom: -3px; width: 12px; }
.text-box .tb-edge.right  { right: -3px; top: -3px; bottom: -3px; width: 12px; }

/* Хваталка перемещения (правый верхний угол) */
.text-box .tb-handle {
  position: absolute; top: -14px; right: -14px;
  width: 30px; height: 30px; z-index: 30;
  display: none; align-items: center; justify-content: center;
  background: #10b981; color: #fff; border-radius: 50%;
  font-size: 16px; line-height: 1; cursor: move;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  touch-action: none; user-select: none; -webkit-user-select: none;
  pointer-events: auto;
}
.text-box.selected .tb-handle { display: flex; }
  /* Кнопка дублирования (сверху, слева от поворота) */
.text-box .tb-copy {
  position: absolute; top: -40px; left: 50%;
  transform: translateX(-50%) translateX(-34px);
  width: 26px; height: 26px; z-index: 31;
  display: none; align-items: center; justify-content: center;
  background: #3b82f6; color: #fff; border-radius: 50%;
  font-size: 13px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  user-select: none; -webkit-user-select: none;
  pointer-events: auto;
}
.text-box.selected .tb-copy { display: flex; }

/* ❌ Крестик удаления (левый верхний угол) */
.text-box .tb-delete {
  position: absolute; top: -14px; left: -14px;
  width: 30px; height: 30px; z-index: 30;
  display: none; align-items: center; justify-content: center;
  background: #ef4444; color: #fff; border-radius: 50%;
  font-size: 16px; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  user-select: none; -webkit-user-select: none;
  pointer-events: auto;
}
.text-box.selected .tb-delete { display: flex; }

/* ЭТАП 5: уголок изменения ширины плашки */
.text-box .tb-resize {
  position: absolute; right: -6px; bottom: -6px;
  width: 24px; height: 24px; z-index: 30;
  display: none; cursor: nwse-resize;
  touch-action: none; pointer-events: auto;
}
.text-box .tb-resize::after {
  content: ''; position: absolute; right: 4px; bottom: 4px;
  width: 12px; height: 12px;
  border-right: 3px solid #10b981;
  border-bottom: 3px solid #10b981;
  border-radius: 2px;
  filter: drop-shadow(0 0 2px rgba(0,0,0,.6));
}
.text-box.selected .tb-resize { display: block; }
  /* ЭТАП 6: ручка вращения плашки */
.text-box .tb-rotate {
  position: absolute; top: -40px; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 26px; z-index: 31;
  display: none; align-items: center; justify-content: center;
  background: #3b82f6; color: #fff; border-radius: 50%;
  font-size: 14px; line-height: 1; cursor: grab;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  touch-action: none; user-select: none; -webkit-user-select: none;
  pointer-events: auto;
}
.text-box.selected .tb-rotate { display: flex; }
.text-box:not(.selected) .tb-reset-rot,
.text-box:not(.selected) .tb-90-rot { display: none !important; }


/* Кнопки поворота плашки на компьютере: те же две функции, что на телефоне. */
@media (min-width: 821px) {
  .text-box .tb-reset-rot,
  .text-box .tb-90-rot {
    position: absolute; bottom: -40px; height: 30px;
    border-radius: 15px; background: rgba(239, 68, 68, 0.94); color: #fff;
    border: 2px solid rgba(255,255,255,0.85); text-align: center;
    cursor: pointer; z-index: 32; box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    touch-action: manipulation; user-select: none; pointer-events: auto;
    padding: 0; font-weight: 700; white-space: nowrap; line-height: 26px;
  }
  .text-box .tb-reset-rot { left: calc(50% - 40px); width: 32px; font-size: 18px; }
  .text-box .tb-90-rot { left: calc(50% + 5px); width: 38px; font-size: 13px; }
  .text-box .tb-reset-rot:active,
  .text-box .tb-90-rot:active { background: rgba(220,38,38,1); transform: scale(0.93); }
}

/* Дополнительные кнопки поворота — только телефон. */
@media (max-width: 820px) {
  .text-box .tb-reset-rot,
  .text-box .tb-90-rot {
    position: absolute;
    bottom: -44px;
    height: 34px;
    border-radius: 18px;
    background: rgba(239, 68, 68, 0.94);
    color: #fff;
    border: 2px solid rgba(255,255,255,0.85);
    text-align: center;
    cursor: pointer;
    z-index: 32;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    touch-action: manipulation;
    user-select: none; -webkit-user-select: none;
    pointer-events: auto;
    padding: 0;
    font-weight: 700;
    white-space: nowrap;
  }
  .text-box .tb-reset-rot {
    left: calc(50% - 50px);
    width: 38px;
    font-size: 21px;
    line-height: 30px;
  }
  .text-box .tb-90-rot {
    left: calc(50% - 4px);
    width: 42px;
    font-size: 15px;
    line-height: 30px;
  }
  .text-box .tb-reset-rot:active,
  .text-box .tb-90-rot:active {
    background: rgba(220,38,38,1);
    transform: scale(0.93);
  }
}

#imgMiniBar {
  position: fixed; z-index: 5000; display: none;
  background: #171a21; border: 1px solid #3d7eff; border-radius: 10px;
  padding: 6px; gap: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.5);
  flex-wrap: nowrap; align-items: center;
}
#imgMiniBar.visible { display: flex; }
#imgMiniBar button {
  min-width: 34px; height: 34px; padding: 0 6px; margin: 0;
  background: #2a2f3a; color: #fff; border-radius: 7px; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
#imgMiniBar button:hover { background: #3d7eff; }
#imgMiniBar .mb-div { width: 1px; height: 22px; background: #4a5568; margin: 0 2px; }

#imgSettings { display: none; background: #2a2f3a50; padding: 12px; border-radius: 8px; margin-top: 12px; }
#imgSettings.visible { display: block; }
#imgSettings label { color: #cdd5df; }
#imgSettings .is-row { display: flex; align-items: center; gap: 8px; }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: #171a21; width: 500px; padding: 20px; border-radius: 12px; border: 1px solid #2a2f3a; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 10px 0; font-size: 18px; color: #fff; }
.modal textarea { width: 100%; height: 120px; background: #0f1115; color: #e8e8e8; border: 1px solid #2a2f3a; border-radius: 8px; padding: 10px; font-family: monospace; font-size: 14px; resize: none; margin-bottom: 10px; }
#previewImage { width: 100%; max-height: 250px; object-fit: contain; border-radius: 8px; border: 1px solid #2a2f3a; margin-bottom: 10px; background: #0f1115; display: none; }

#zoomControls {
position: fixed; bottom: 20px; right: 20px; z-index: 400;
display: flex; align-items: center; gap: 6px;
background: rgba(23, 26, 33, 0.95); padding: 8px 10px;
border-radius: 12px; border: 1px solid #2a2f3a; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
#zoomControls button {
width: 40px; height: 40px; background: #2a2f3a; color: #fff;
font-size: 18px; padding: 0; display: flex; align-items: center; justify-content: center;
}
#zoomControls button:hover { background: #3d7eff; }
#zoomLabel {
min-width: 52px; text-align: center; font-size: 14px; font-weight: bold; color: #e8e8e8; user-select: none;
}

#panelHandle, #mobileToolsBtn { display: none; }

/* Плавающие Undo/Redo — на ПК сразу справа от панели, на холсте */
#floatUndoRedo {
  position: fixed; top: 12px; left: 392px; z-index: 4500;
  display: flex; gap: 6px;
}
#floatUndoRedo button {
  width: 40px; height: 40px; padding: 0;
  background: rgba(23, 26, 33, 0.95); color: #fff;
  border: 1px solid #2a2f3a; border-radius: 10px;
  font-size: 17px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
#floatUndoRedo button:hover:not(:disabled) { background: #3d7eff; }
#floatUndoRedo button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== КАРТИНКА ВНУТРИ ПЛАШКИ: обёртка и уголок растягивания ===== */
.text-box .tb-img-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
.text-box .tb-img-wrap img.tb-img { margin: 4px 0; }
.text-box .tb-img-grip {
  position: absolute; right: -6px; bottom: 0;
  width: 26px; height: 26px; z-index: 25;
  display: none; cursor: nwse-resize;
  touch-action: none; pointer-events: auto;
}
.text-box .tb-img-grip::after {
  content: ''; position: absolute; right: 6px; bottom: 8px;
  width: 12px; height: 12px;
  border-right: 3px solid #10b981;
  border-bottom: 3px solid #10b981;
  border-radius: 2px;
  filter: drop-shadow(0 0 2px rgba(0,0,0,.7));
}
.text-box.selected .tb-img-grip { display: block; }

@media (max-width: 820px) {
body { display: block; height: 100vh; overflow: hidden; }
  /* Телефон: ползунки размера и интервала — друг под другом на всю ширину */
.dual-slider-row {
  flex-direction: column !important;
  gap: 4px !important;
}
.dual-slider-row > div {
  width: 100% !important;
  flex: 1 1 100% !important;
}
.dual-slider-row input[type=range] {
  width: 100% !important;
  height: 32px;
}
.stage { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding: 15px; }

#floatUndoRedo {
  position: fixed !important;
  top: calc(10px + env(safe-area-inset-top, 0px)) !important;
  left: calc(10px + env(safe-area-inset-left, 0px)) !important;
  right: auto !important;
  bottom: auto !important;
  z-index: 100000 !important;
  touch-action: manipulation;
  /* transform здесь НЕ обнуляем: на iPhone им доводит положение core.js.
     Раньше стояло transform:none !important, и доводка не срабатывала. */
  transform-origin: top left;
  /* кнопки не должны прокручиваться и подсвечиваться при касании */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#mobileToolsBtn {
display: flex; align-items: center; justify-content: center;
position: absolute; top: 60px; left: 10px; z-index: 1000;
background: #171a21; color: #fff; border: 1px solid #2a2f3a;
padding: 0 10px; height: 36px; border-radius: 10px; font-size: 12px; font-weight: bold;
box-shadow: 0 4px 10px rgba(0,0,0,0.3); cursor: pointer;
}
#mobileToolsBtn:active { background: #2a2f3a; }

.panel {
position: fixed; top: 0; left: -320px; width: 320px; height: 100%;
z-index: 2000; transition: left 0.3s ease; box-shadow: 5px 0 20px rgba(0,0,0,0.8);
padding: 15px; border-right: none;
background: rgba(23, 26, 33, 0.55) !important;
-webkit-backdrop-filter: none !important;
backdrop-filter: none !important;
}
.panel.open { left: 0; }
#panelHandle {
display: flex; align-items: center; justify-content: center;
position: fixed; top: 30%; left: 0; transform: translateY(-50%);
width: 34px; height: 70px; z-index: 2001;
background: #171a21; border: 2px solid #3d7eff; border-left: none;
border-radius: 0 12px 12px 0; color: #3d7eff;
font-size: 22px; font-weight: bold; padding: 0;
box-shadow: 3px 0 8px rgba(0,0,0,0.4);
transition: left 0.3s ease;
}
#panelHandle.open { left: 320px; }
.panel h1 { display: none; }
.toolbar button { min-width: 34px; height: 34px; font-size: 15px; }
.emoji-bar span { font-size: 24px; padding: 5px; }
#zoomControls { display: none !important; }
.modal { width: 92%; max-width: 500px; }
.emoji-wrap, label[style*="😀 Эмодзи"] { display: none !important; }
#imgMiniBar { display: none !important; }

/* Ручки плашки на телефоне те же, что на компьютере, только крупнее:
   палец уверенно попадает примерно с 40 пикселей. Рёбра рамки не нужны —
   за них тянут мышью, пальцем для этого есть хваталка. */
.text-box .tb-edge { display: none !important; }
/* Зелёная рамка — зона захвата: 4 широких ребра, не выходят за плашку.
   Центр остаётся доступным для текста и его выделения. */
.text-box.selected .tb-drag-frame {
  display: block !important;
  inset: 0 !important;
  pointer-events: none !important;
}
.text-box .tb-edge {
  display: block !important;
  pointer-events: auto !important;
  touch-action: none;
}
.text-box .tb-edge.top    { top: 0 !important; left: 0 !important; right: 0 !important; height: 14px !important; }
.text-box .tb-edge.bottom { bottom: 0 !important; left: 0 !important; right: 0 !important; height: 14px !important; }
.text-box .tb-edge.left   { left: 0 !important; top: 0 !important; bottom: 0 !important; width: 14px !important; }
.text-box .tb-edge.right  { right: 0 !important; top: 0 !important; bottom: 0 !important; width: 14px !important; }
/* Управляющие значки не участвуют в геометрии плашки и не создают ограничений. */
.text-box .tb-copy,
.text-box .tb-delete,
.text-box .tb-rotate,
.text-box .tb-resize,
.text-box .tb-reset-rot,
.text-box .tb-90-rot { pointer-events: auto; }

.text-box.selected .tb-handle,
.text-box.selected .tb-delete {
  width: 40px !important; height: 40px !important; font-size: 19px !important;
}
.text-box .tb-handle { top: -20px !important; right: -20px !important; }
.text-box .tb-delete { top: -20px !important; left: -20px !important; }

.text-box.selected .tb-rotate,
.text-box.selected .tb-copy {
  width: 38px !important; height: 38px !important;
  font-size: 17px !important; top: -50px !important;
}
.text-box .tb-copy { transform: translateX(-50%) translateX(-44px) !important; }

.text-box .tb-resize {
  width: 40px !important; height: 40px !important;
  right: -12px !important; bottom: -12px !important;
}
.text-box .tb-resize::after {
  right: 6px !important; bottom: 6px !important;
  width: 16px !important; height: 16px !important;
  border-right-width: 4px !important; border-bottom-width: 4px !important;
}

/* Пока тянем ручку — текст внутри не должен перехватывать палец. */
.text-box.tb-busy .tb-content { pointer-events: none; }

/* Уголок картинки в плашке — тоже под палец. */
.text-box .tb-img-grip {
  width: 40px !important; height: 40px !important; right: -10px !important;
}
.text-box .tb-img-grip::after {
  right: 8px !important; bottom: 12px !important;
  width: 15px !important; height: 15px !important;
  border-right-width: 4px !important; border-bottom-width: 4px !important;
}
  
/* iPhone: разрешить курсор внутрь слова */
#editor { word-break: break-word; }

  /* ===== ПЛАШКА НА ТЕЛЕФОНЕ (только мобайл, компьютер не затрагивается) =====

     1. Выделение текста. На .text-box стоит user-select: none — на компьютере
        он нужен, чтобы перетаскивание мышью не выделяло текст. Пальцем тянут
        за ручки, а запрет мешал растянуть выделение дальше одного слова. */
  .text-box { -webkit-user-select: text; user-select: text; }
  .text-box .tb-content,
  .text-box .tb-content *:not(img) {
    -webkit-user-select: text; user-select: text;
    -webkit-touch-callout: default;
  }
  /* Пока тянем ручку — выделения быть не должно. */
  .text-box.tb-busy,
  .text-box.tb-busy *:not(img) {
    -webkit-user-select: none !important; user-select: none !important;
  }

  /* 2. Тулбар и выбор шрифта плашки не нужны в шторке: текстом управляет
        quickBar. Размер, интервал, цвет, прозрачность, картинка и подложка
        остаются на месте. */
  #tbSettings .tb-toolbar { display: none !important; }
  #tbSettings .tb-font-row { display: none !important; }
}

#quickBar {
display: none; position: fixed; left: 0; bottom: 0; width: 100%; z-index: 99999;
background: #1c2129; border-top: 2px solid #3d7eff; padding: 6px; gap: 6px;
overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; box-sizing: border-box;
}
#quickBar.visible { display: flex; flex-wrap: nowrap; align-items: center; }
#quickBar button {
flex: 0 0 auto; min-width: 42px; height: 42px; margin: 0; padding: 0;
font-size: 18px; border-radius: 10px; background: #2a2f3a; color: #e6ebf2;
border: 1px solid #3a4150; display: flex; align-items: center; justify-content: center;
}
#quickBar button:active { background: #3d7eff; }

#quickBar input[type=color] {
flex: 0 0 auto; width: 42px; height: 42px; margin: 0; padding: 2px;
border-radius: 10px; background: #2a2f3a; border: 1px solid #3a4150;
cursor: pointer; overflow: hidden;
}

.stage.hand-mode #editor { cursor: grab; }
.stage.hand-mode.panning #editor { cursor: grabbing; }
#modeBtn.active { background: #10b981 !important; }

/* ===== ТЕЛЕФОННАЯ ПЛАВАЮЩАЯ МЕНЮ КАРТИНКИ ===== */
#imgMobilePanel {
  position: fixed; z-index: 6000; display: none;
  width: 270px; max-width: 90vw;
  background: rgba(23, 26, 33, 0.78);
  border: 1px solid #3d7eff; border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
  padding: 0 12px 12px; color: #e8e8e8;
  touch-action: none;
}
#imgMobilePanel.visible { display: block; }
#imgMobilePanel .imp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0 8px; cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 8px;
}
#imgMobilePanel .imp-head.grabbing { cursor: grabbing; }
#imgMobilePanel .imp-title { font-size: 13px; font-weight: bold; color: #4ade80; }
#imgMobilePanel .imp-close {
  width: 26px; height: 26px; border-radius: 6px; background: #2a2f3a; color: #fff;
  font-size: 15px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
#imgMobilePanel label { color: #cdd5df; font-size: 11px; margin: 8px 0 3px; font-weight: bold; display: block; }
#imgMobilePanel input[type=range] { width: 100%; margin: 0; }
#imgMobilePanel input[type=color] { width: 100%; height: 32px; border-radius: 6px; }
#imgMobilePanel .imp-btns { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
#imgMobilePanel .imp-btns button {
  flex: 0 0 auto; min-width: 34px; height: 34px; padding: 0 6px; margin: 0;
  background: #2a2f3a; color: #fff; border-radius: 7px; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
#imgMobilePanel .imp-btns button:active { background: #3d7eff; }
#imgMobilePanel .imp-rot-row { display: flex; gap: 6px; align-items: center; }
#imgMobilePanel .imp-rot-row button { flex: 0 0 auto; width: 34px; height: 32px; background:#2a2f3a; color:#fff; }

/* ЭТАП 2: тост-подсказка для плашек на телефоне */
#tbToast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(23,26,33,0.96); color: #fff; border: 1px solid #10b981;
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 100000;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  max-width: 80vw; text-align: center;
}
#tbToast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ПРИВЯЗКА: направляющие линии центра холста */
.snap-guide {
  position: absolute; z-index: 40; pointer-events: none;
  background: #ff2d95; opacity: 0; transition: opacity .08s;
}
.snap-guide.visible { opacity: 0.9; }
.snap-guide.vertical { width: 2px; top: 0; bottom: 0; }
.snap-guide.horizontal { height: 2px; left: 0; right: 0; }


/* Редакторские кнопки и ручки никогда не попадают в PNG. */
.exporting .tb-handle, .exporting .tb-copy, .exporting .tb-delete,
.exporting .tb-resize, .exporting .tb-rotate, .exporting .tb-drag-frame,
.exporting .tb-edge, .exporting .tb-img-grip,
.exporting .tb-reset-rot, .exporting .tb-90-rot { display: none !important; }
