:root {
  --bg: #f4f4f5;
  --panel: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --accent: #4f46e5;
  --line: #e4e4e7;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header { padding: 20px 24px 0; }
h1 { margin: 0 0 4px; font-size: 24px; }
.sub { margin: 0; color: var(--muted); }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 20px 24px;
  align-items: start;
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.stage-wrap { min-width: 0; }

.dropzone {
  border: 2px dashed #c4c4cc;
  border-radius: 14px;
  background: var(--panel);
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}
.dropzone.drag { border-color: var(--accent); background: #eef2ff; }
.dropzone strong { color: var(--ink); }

.stage {
  position: relative;
  display: inline-block;
  overflow: hidden;           /* обрезаем надпись по краям, как в итоговом файле */
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  max-width: 100%;
}
.stage[hidden] { display: none; }
.stage img {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  -webkit-user-drag: none; /* иначе промах мимо надписи начинает drag картинки */
  user-select: none;
}
.stage.drag { outline: 3px dashed var(--accent); }

/* Геометрия надписи повторяет серверный рендер:
   line-height 1.25 и padding 0.15em/0.3em — те же константы в render.py */
.caption {
  position: absolute;
  transform: translate(-50%, -50%);
  line-height: 1.25;
  white-space: pre;
  padding: 0.15em 0.3em;
  border-radius: 0.22em;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.caption:focus-visible {
  outline: 2px dashed rgba(79, 70, 229, 0.9);
  outline-offset: 2px;
}
/* выбранная надпись всегда подсвечена рамкой (только в предпросмотре) */
.caption.active {
  outline: 1.5px dashed rgba(79, 70, 229, 0.85);
  outline-offset: 2px;
}

.hint { color: var(--muted); font-size: 13px; margin: 10px 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
}
.field textarea,
.field select {
  font: inherit;
  font-weight: 400;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
  background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.val { color: var(--muted); font-weight: 400; }

.btn-row { display: flex; gap: 6px; }

button { font: inherit; cursor: pointer; }

.toggle {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 38px;
}
.toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle:disabled { opacity: 0.4; cursor: not-allowed; }

.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
}
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.linklike {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  text-decoration: underline;
  font-size: 13px;
}
.linklike:disabled { color: var(--muted); text-decoration: none; cursor: not-allowed; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 400;
  font-size: 13px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.add { font-weight: 700; min-width: 34px; }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }

.status { min-height: 1.4em; margin: 0; font-size: 13px; color: var(--muted); }
.status.error { color: var(--danger); }

input[type="color"] {
  inline-size: 44px;
  block-size: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
input[type="range"] { width: 100%; }

#hl-opts { display: flex; flex-direction: column; gap: 14px; }
#hl-opts.hidden { display: none; }
